I realise there are several queries on here for this same problem but none of them provide a solution to my particular problem.
I am running a web driver test that tries to fill out a form for a mail website to find postcodes based on address details. I keep getting this error when trying to locate the first text box:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#ctl00_BodyContent_txtBuildingNumber"}
I have used xpath and the id to try and locate the element but I keep getting the error. I can see that this element is present when the webdriver is running and I have been able to locate another text element on the page and enter text, but I keep getting this error for this field and other fields within the frame.
I am guessing that the problem must be to do with the fact that this field is part of an iFrame.
I have used implicit waits within the test but with no success. I still get the error.
findElement method is used to access a single web element on a page. It returns the first matching element. It throws a NoSuchElementException exception when it fails to find If the element.
isDisplayed() is the method used to verify presence of a web element within the webpage.
Get Command It accepts String as parameter and returns void. The respective command to load a new web page can be written as: driver. get(URL);
By the sounds of it you'll need to first switch to the iframe
element that contains the element that you want to interact with. (Although without seeing the relevant HTML this is a bit of an extrapolated guess).
driver.switchTo().frame();
eg:
driver.switchTo().frame(1);
driver.switchTo().frame(driver.findElement(By.id("id")));
When you've finished interacting with the elements within the frame, you'll need to switch back to the main webpage.
driver.switchTo().defaultContent();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With