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.
Related
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.
Recently I have been tasked with Automating MS CRM 365 with Selenium Automation. I have opted for Using Gradle and Java for this, using IntelliJ.
Currently my issue is when I am on a form page, I am unable to access any elements on that page for data entry or drop-down selection.
I have tried using iFrame switching:
driver.switchTo().frame(driver.findElement(By.cssSelector("#contentIFrame0")));
I have tried selecting from ID, from XPATH & from CSS.
The code is a simple driver.findElement; there isn't anything special about it. I seem to be failing at the most basic part.
driver.findElement(By.id("firstname_i")).click();
Expected outcome: To be able to access the element and process a Click, followed by either a selection from drop-down or a text entry.
Actual outcome:
org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #firstname_i
Image to Firefox Inspection of the Element
I was wondering if there is something in the CSS that's stopping me from accessing the element. I noticed that the element for the 'text' box is under a few layers and is not displayed, unless the top layer is accessed. However I cannot event find that element to follow the flow. Hope that makes some sense.
So after a bit of playing about, I noticed that my iframe switch was working however the element I was trying to access was correct just not complete, not sure if this is ever relevant to anyone else but I had to add a method to counter my element issue by select the initial element "name" and then selecting a second element as the input "name_i".
Where as if I tried to select "name_i" initially I get the whole "element not found" as the CSS sets it to invisible unless activated by mouse over/ click on the first element (overlay?).
This seems to be the case across the whole form page.
Never worked with MS 365 before so I have no idea if this is viable or even common.
Thanks.
Hopefully someone can help me with a solution to my problem. I have spent the better part of the day trying nearly every solution I can find on here and through Google.
I will cut to the chase. I have a test that logs in on one screen. The second screen selects a role and moves on. I am able to get to the role selection screen, but cannot move forward as Selenium will not click the button, regardless of what I do.
The interesting thing is that this will work with the IDE, but exporting the code to java and running it with the webdriver does not work either. This part makes no sense to me as I would think the IDE export should run easily. The only difference I can see is that the webdriver pulls up a profile-less Firefox, whereas the IDE is running on my profile - not sure that this would have anything to do with it, but wanted to throw that out there.
The only difference between the first button and the second button is the autofocus command in the HTML.
<button data-submit-button="" class="btn" autofocus="" name="submit" type="submit">Go</button>
I've tried numerous solutions found throughout the web and the last thing I've tried is
new WebDriverWait(driver,120).until(ExpectedConditions.elementToBeSelected(By.name("submit")));
driver.findElement(By.name("submit")).click();
This does not work either. I have tried several variations on this and most of the time the webdriver either times out or skips through this step, passing it and then failing on the next steps as the page has not moved forward.
Does anyone have any suggestions? If you have any questions or I can give you more information if I haven't given enough! Any help with this would be amazing, as I've spent the better part of the day trying to get through this one issue.
Thanks!
Sometimes the selector is the main issue in the scenario like this. Also, name="submit" is not even a very safe selector to use since developers have tendency to duplicate the same attribute across the form. Without knowing about the actual elements I can pretty much tell you the issue is the selector. If the text Go is the only text of the button on that page, give the following xpath a shot
//button[#name='submit'][#type='submit'][contains(text(),'Go')]
Complete implementation should look like as follows:
By xpath = By.xpath("//button[#name='submit'][#type='submit'][contains(text(),'Go')]");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(xpath));
myDynamicElement.click();
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.
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