I have a simple HTML webpage that has text field (no IFrames that I can see) nested inside some divs and a </form>
. I'm sure I am using the correct ID but when running the code in IntelliJ it keeps failing. This is the html of the element. This is the exception I get:
exception
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="loginLastName"]"}
And the HTML of the element (text field) I am trying to locate via selenium:
HTML:
<input type="text" maxlength="32" minlength="2" required="" id="loginLastName" class="grv-input " aria-describedby="loginLastNameAria" pattern="(([ \-.']*)?[A-Za-z]+([ \-.']*)?)*">
And in the java code, my browser is correctly loading to dummy sites like http://google.com
but failing to grab the elementId off my site in question. I tried with ID and with XPATH (which I got from chrome browser):
Java
// get by ID
driver.findElement(By.id("loginLastName")).sendKeys("This is a test");
// get by XPATH
driver.findElement(By.xpath("//*[@id=\"loginLastName\"]")).sendKeys("dsdfdsfdsdsdsfdsgsdfgsdfdsg");
I also tried adding a delay to make sure the component had time to load, but nothing changes
WebDriverWait wait = new WebDriverWait(driver, 100);
element = wait.until(ExpectedConditions.elementToBeClickable(By.id("loginLastName")));
Does it matter this is nested in within two <divs>
and a <form>
? Do I have to iterate through those elements, to get down to this one or something? (seems overly complicated, though I haven't worked that much with selenium).
Let me know!