1

I've searched through stack overflow and while there are answers to "org.openqa.selenium.NoSuchElementException: Unable to locate element" they don't seem to fit in my situation. I am very new to coding and using selenium. So any help you can provide would be awesome. Thank you in advance.

I am getting this error when I am finding an element which is a user name text box.

When I inspect the element with firepath I get the following;

input id="txt_658_4692" class="form-control ggo-field" required="1" data-bv-notempty-message="The field is required." data-bv-stringlength-message="255 characters to be removed." data-fv-stringlength="true" maxlength="255" data-ggo-maxlength="255" name="txt_658_4692" data-ggo-fieldtype="TEXT" data-ggo-fieldidentifier="APPLICANT_USERNAME" data-ggo-token="de6cbe2fe346a847ab301bd6147c0374" value="" type="text"/

So somewhere in that string of crazy is supposed to be the element that I can target to then send keys to log in.

I've tried using

driver.findElement(By.Id())
driver.findElement(By.xpath())
driver.findElement(By.cssSelector())
driver.findElement(By.name())

This is the portion of code that I am getting an error on

WebElement usernameTextbox = driver.findElement(By.xpath(".//*[@id='txt_658_4692']"));
    usernameTextbox.sendKeys("russelltest1");

Any help or suggestions would be great.

Thank you.

rcorless
  • 11
  • 1

2 Answers2

1

NoSuchElementException is thrown when webdriver can't find element in DOM. I assume that your textbox element id probably changes dynamically so this xpath query can't select it because it's not there anymore. Try with different xpath selector, something like:

driver.findElement(By.xpath(".//*[data-ggo-fieldidentifier='APPLICANT_USERNAME']"));

See if it helps.

acikojevic
  • 915
  • 1
  • 7
  • 16
  • I ended up finding it with driver.findElement(By.xpath(".//*[@id='txt_658_4692']")); When I was looking at the console it kept giving me something close to that but cut off. Just a matter of trial and error. Thank you for taking the time to answer my question. I appreciate it. – rcorless Jan 03 '17 at 23:11
0

You can also identify the text box using the label text. For example, if your username field label has text property as User:, you can locate the text box using following xpath:

//label[text()='User:']/following::input[1]

or

//*[text()='User:']/following::input[1]

In case, it does not work for you, please share the complete HTML for the page, so that, I can tell you the exact path for the required text box.

Mahipal
  • 900
  • 1
  • 5
  • 7