Selenium Sendkeys fails to work in second attempt in IE9 - java

I am facing an issue with Selenium SendKeys. I created a separate method in Java for sending the details to be filled in for a window using Sendkeys. During first attempt it enters all the configured details and was working fine.
I use the same method after few lines in my code for entering another set of details. But this time it fails to enter the details in window. I can see selenium entering the text and switching to the next tabs, but the text is not visible. I don't see any exception as well.
Can someone please help me with this. Also I am using selenium web driver with IE9.
Thank you,
Raj

Try Using driver.findElement(By.id("element")).clear(); before sending SendKeys
You are saying it is Entering the text and Switching to Next Tab , IS it entering the Expected values ??? which Text is Not Visible ? the Entered one ? if No Exception - the AUT is Designed to Hide the Second entered Text ?
Provide snippets of Code to Check whats happening with the driver

Related

Can we use one pageobject among different pages?

I am working on one selenium project. My scenario is, I have multiple forms one after another. After filling them I have to click on the Next button. I have 4 pages with the next button and they have the same XPath. When I try to use the same web element for the next button it works once but when I try to use that same thing again on a different page It shows element intreactable error.
I would try the following to identify why you get the interactable error (it would help to give us the error at least as is found on the Selenium Documentation)
try to click using javascript executor,
try to add webelements for each action you need to perform (so 4 webelements for each 'Next' button). If it works in this way maybe the webelement is not refreshed after you use it (maybe is a static field). Try also to work with Page Factory pattern.
If nothing works, we should receive more information to be able to help.

I dont understand this output produced by selenium webdriver java

I'm trying to write an application for the game Path of Exile, that lists the items in my stash on trading websites automatically.
For this I have to retrieve the items in my stash from their website. For some reason the ".getText()" functions is behaving very weird on the website. I really can't see any mistakes I did with the x-path Expressions.
Example:
Here you can see a snippet from the HTML file I am working on
screenshot of browser debugg tool
In the screenshot you can see that the x-Path I am using is selecting a element with a text element, however when I iterate over the elements and get the text with the getText() function, it returns a empty String... I really have no clue what I am doing wrong, is it the website, that is denying me to access the field?
In case it helps I add here a screenshot of the source code for outputting the text fields
printing the text of the elements(SourceCode)
5 empty Strings as output
On your place I would try to get value instead of text.
try to replace
e.getText()
with
e.getAttribute("value")
or you can also try to play with .getCssValue()

Unable to retrieve Textbox Value In Selenium Testing

I am new to Selenium testing, I am trying to put the value into the textbox with the help of xpath, name & id. (java using eclipse IDE):
driver.findElement(By.xpath(".//* [#id='txtEmpDepAddressLine1']")).sendKeys("2nd Main")
driver.findElement(By.xpath(".//*[#id='txtEmpDepAddressLine2']")).sendKeys("Bangalore");
While running, textbox is not retrieve the from the above code. Can anyone help me out to solve this problem?
Use By.id instead By.xpath
If you insist xpath then:
Start with: // instead: .//
Make sure the id value is unique on page.
if using xpath in some browsers id or ID makes differnce.
It is difficult to say without the HTML, but I'd suggest a few things:
Open your page, go to the Google Chrome DevTools console, and verify you can locate the element using your xpath. So you'd type:
$x("//* [#id='txtEmpDepAddressLine1']")
and verify the text box is located.
If the sendKeys isn't working on the element at that id, I'd wonder if it is not on the text field itself, but on a containing table or something like that. Make sure the element located by the id is the input, so the sendKeys will work.
By
In the text box it is fetching the value but it can't able not store
in the text box field
do you mean you can see selenium typing those values into the textbox and then the values disappear?
If that is what is happening, it is possible there is some javascript running on the page while selenium is entering the values in the textbox. you can try to put a wait before selenium enters the value. If waiting resolves the issue, you will need to write a method to detect when the javascript is done.

Selenuim WebDriver bug? ChromeDriver not focusing on field when setting value?

I've been struggling with this one today;
I have an input field that has some custom JavaScript that displays a 'hint' piece of text when the field's value is empty and the user has not clicked on the field (i.e. focused on it). Otherwise it disappears.
As of a few days ago the following code worked fine with the input field with this hint JS:
WebDriver driver = chromeDriver;
WebElement fieldWithHint = driver.findElement(By.id("myField"));
fieldWithHint.sendKeys(newValue);
Today it doesn't work (since I have restarted my machine) - the hint JS gets very confused and on entering the text, and moving to the next field, then displays the text as the hint.
I have just discovered that the following does still work:
WebDriverBackedSelenium driverWrapper = new WebDriverBackedSelenium(chromeDriver, "http://localhost/");
WebElement fieldWithHint = chromeDriver.findElement(By.id("myField"));
driverWrapper.type(fieldWithHint.getAttribute("name"), newValue);
I am using WebDriver for Java (version 0.9.7376), the latest ChromeDriver (2.9) and Chrome version 34.0.1847.116 m.
I wonder whether restarting my computer, and hence restarting Chrome, has updated it and caused this issue.
Has anyone else seen this? Is it a known issue?
I have tried first clicking in the field to no avail.
I have just had a related issue since upgrading to v34.
I have a page of input fields, each linked to an onblur event, which I trigger via a tab out of the input.
before the upgrade, this worked fine, now tabbing out of the last field, doesn't trigger the event.
A manual tab takes focus to the address bar, where as a selenium tab goes to the first element in the DOM. I have not yet performed the same investigation on v33 nor have I raise a defect.
I know this is linked to the upgrade as it was failing on Grid nodes which had auto updated but was fine locally until I upgraded
***EDIT***
Managed to reproduce and raised with Chromedriver (https://code.google.com/p/chromedriver/issues/detail?id=762)
My issue is that if you send :tab and this results in focus being shifted to address bar, then focus does not get reapplied to elements even if you interact with them.

Is it possible to enter a text in a textbox without specific Element ID

Im doing a test that enter text in the textbox but it dont have specific ID so everytime i run the test it will change. im using selenium webdriver in java please help
The following can work. You can google for them and see how they work.
driver.findElement(By.id("id"));
driver.findElement(By.cssSelector("cssSelector"));
driver.findElement(By.name("name"));
driver.findElement(By.linkText("linkText"));
driver.findElement(By.partialLinkText("partialLinkText"));
driver.findElement(By.className("className"));
driver.findElement(By.xpath("xpath"));
I am sure some of them will be useful. Please let me know if you want more info.
The easiness of using them is in the order which i have mentioned.
What means doesn't have a specific ID?If id at least partially remains the same you can use the CSS locator
driver.findElement(By.cssLocator("input[id*=somePartWhichNotChange]"));
//* star means contains
if not, then you can use cssSelector to get to your element like "body table input" or use xpath as a last resort.

Categories