xpath in firebug works however sendkey is not sending value - java

I am trying to write a login code for hotmail. I asked this a few days ago on how to get the xpath, someone answered and gave me the correct xpath in his reply:
//*[#id='CredentialsInputPane']//div[3]//div[2]/div
His answer worked.
Today I tried to come up with my own xpath solution and in Firepath when I use the following syntax it highlights the user name field.
//div[contains(#class,'placeholder has-focus')][text()='Email, phone, or Skype name']
Question/problem: When I run the test, in UI it does not send the value user#msn.com, it clicks the Next button and I get error "Please enter a value".
What is wrong with my xpath syntax, even though it is highlighting the field? Why is it not sending the email id?
Code:
driver.get("https://login.live.com/login.srf?");
driver.findElement(By.xpath("//div[contains(#class,'placeholder')][text()='Email, phone, or Skype name']")).sendKeys("usertest81#msn.com");
driver.findElement(By.xpath("//input[contains(#id,'idSIButton9')]")).click();
Thanks in advance for your time and explanation.

You are trying to send value to a non-input field. This may be the reason. Try with the following-
driver.findElement(By.name("loginfmt")).sendKeys("usertest81#msn.com");

Related

Google App Script logger.log not showing anything

I writing a simple google web app. this .gs basically open a html file that require user to input his name then click. after the user clicked it, the function checkGCR() should log the username in logger.log. but nothing show in logger.log. if run the function checkGCR(), the log does record "null" since nothing input in the input box. One thing I notice is eventhough the logger.log didn't show anything, but stackdriver log doesn't showing something going on there. Please check my code is that something wrong I did here because I follow online tutorial with exact same coding but logger.log just doesn't seem to work.
//This is code.gs
function checkGCR(myid){
Logger.log(myid);
}
//This is html
document.getElementById("btn").addEventListener("click", doStuff);
function doStuff(){
var myid=document.getElementById("mykidid").value;
google.script.run.checkGCR(myid);
}
I just found out that eventhough it doesn't show up at Logger.log, but it does show up in Stackdriver log. So I just use that instead.

Popup messages with selenium webdriver

I'm testing a website with validation etc. when the user types something incorrectly in each field and clicks save, a popup with the information appears. All those information are in the functions in the code (there is no JSON) file with them. My question is, how can I test them with selenium so when I'm writing a test script (in Java), so when the script is running they also show up on the console? I hope I explained my problem well.
Get Text From Pop Up:
String popUpText = driver.switchTo().alert().getText();
Accept Pop up Message:
driver.switchTo().alert().accept();

isDisplayed always returns false for the specific element

I'm using Selenium to check if error message shown when user sent form with empty fields. Error message block is attached to the DOM all the time, but when there is no errors it has "display: none;" style attribute. So, when I push the "save" button, I check if this block visible this way:
Assert.assertTrue("There is no validation error!", driver.findElement(By.id("validationModal")).isDisplayed());
And this works. But when I'm trying to check that messages in this block are showed, isDisplayed method always returns "false". When I use just this:
driver.findElement(By.id("validationModal")).findElement(By.tagName("ul"))
.findElement(By.xpath("//*[contains(text(),'Empty app name field')]"));
it goes fine, but it's wrong because it wouldn't throw an exception when this text will be not visible, but will be in page code. If I write this:
Assert.assertTrue(driver.findElement(By.id("validationModal")).findElement(By.tagName("ul"))
.findElement(By.xpath("//*[contains(text(),'Empty app name field')]")).isDisplayed());
it always fails. And I don't really understand why and how I can check, that text of error message is shown, right way.
UPD:
I've found the source of problem. This string finds not element inside "validationModal" block, but inside tag, which contains text we have to find.
driver.findElement(By.id("validationModal")).findElement(By.tagName("ul"))
.findElement(By.xpath("//*[contains(text(),'Empty app name field')]")).isDisplayed()
But I still not understand why it happens, because I specify the element where it should be searched for.
It seems that you are trying to interact with some modal frame.
Generally to interact with modal element you should change driver context first.
driver.switchTo().frame("ModelFrameTitle");
or
driver.switchTo().activeElement()
Find or check elements and then come back to main frame
driver.switchTo().defaultContent()
Try this :
Assert.assertTrue("Element is not displayed",driver.findElement(By.xpath("//*[contains(text(),'Empty app name field')]")).isDisplayed());
There was an error in xpath.
Wrong string was:
findElement(By.xpath("//*[contains(text(),'Empty app name field')]"))
And right is:
findElement(By.xpath("//li[contains(text(),'Empty app name field')]"))

POST Password and Email data to Google Sign-in

All- I have the code:
doc = Jsoup.connect("https://play.google.com/apps/publish/Home?dev_acc=00758402038897917238")
.data("input#Email", "email#gmail.com")
.data("input#Passwd", "123abcABC123" )
.post();
I got his from here: SO question but could not figure out what is wrong. I am getting the sign in page instead of the page displaying all my published apps. I belive the problem might lie in the input#Email and input#Passwd but I am not sure. I don't quite understand what that is supposed to refer to. So my question: how can I login to my developer console using code similar to the one above and what is supposed to go where input#Email and input#Passwd are?
In post you have to use names, not css selectors:
doc = Jsoup.connect("https://play.google.com/apps/publish/Home?dev_acc=00758402038897917238")
.data("Email", "email#gmail.com")
.data("Passwd", "123abcABC123" )
.post();

sendKeys.RETURN not working in FirefoxDriver

if I execute the following code in FireFoxDriver:
WebElement element = driver.findElements(By.id("some_id")); // element being a textbox
element.sendKeys("apple");
element.sendKeys(Keys.RETURN);
The sendKeys(Keys.RETURN) is not performing its desired function.
Actually what I am trying to do is Input a text in a dynamic text search box (like one in facebook search) and press enter. The input is working fine but not the enter key.
sendKeys("apple") works, even sendKeys(Keys.BACK_SPACE) works, but not Keys.RETURN.
Does anyone have ideas? Thanks guys!
Not exactly sure why this happens, but there are a couple alternate ways of doing this that may help:
If elements are in a form, and there is no javascript that runs on submit or something you can use .submit() on any form input element, such as inputs and textareas:
WebElement element = driver.findElements(By.id("some_id"));
element.sendKeys("apple");
element.submit()
You can send the newline character with your input:
WebElement element = driver.findElements(By.id("some_id"));
element.sendKeys("apple\n");
Provide send_keys a list:
WebElement element = driver.findElements(By.id("some_id"));
element.sendKeys("apple", Keys.ENTER);
Got the solution to the above problem. U just need to add, a delay.
This happens because the Java Class runs too fast, so if u have sent a call, and pressed enter/ tab, before the element arrives, the enter is pressed, that is why this doesn't work. Just add Thread.delay(1000); before your Keys.RETURN command. That will do.
Worked for me.
I tried sending \n and fiddled with various commands until I found someone explaining that "keyPress (target) 13" will send the return key.
So first I use type to enter the string I want ...
*
*<tr>
<td>type</td>
<td>id=status</td>
<td>This is my test string</td>
</tr>*
*
... and then send the Enter key to the same text input box
*
*<tr>
<td>keyPress</td>
<td>id=status</td>
<td>13</td>
</tr>*
*

Categories