-1

Hi I'm new to selenium and java. I tried to enter phone numbers in the field but sendkey doesnt work and it gives an error Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element

below is the code I used.

 driver.findElement(By.xpath("//*[@id='content column']/table[1]/tbody/tr/td/form/b/table/tbody/tr/td/table/tbody/tr[2]/td[4]/input")).clear();
 driver.findElement(By.xpath("//*[@id='content column']/table[1]/tbody/tr/td/form/b/table/tbody/tr/td/table/tbody/tr[2]/td[4]/input")).sendKeys("123456789");

Please help me on this.

Saifur
  • 16,081
  • 6
  • 49
  • 73
tony lee
  • 25
  • 4

1 Answers1

0

if your xpath is correct (and if you generated it in google chrome, as it appears you did, then it very likely is correct), then you should try an explicit wait.

often times, your software will run much faster than the page can load, so it's searching for an attribute that isn't present. make your code wait, and report back.

Bee Smears
  • 803
  • 3
  • 12
  • 22
  • idriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); but it sitll gives same error – tony lee Jan 23 '15 at 20:23
  • first, note that there's a difference b/w implicit and explicit waits. `explicit` will wait as long as you've directed it **OR** `until` your attribute is present. second, assuming that 15 seconds is more than enough time for your browser to load the attribute you're seeking, then the problem probably isn't only a `wait` issue. can you please edit your answer to include a code snippet of the html you're looking for? – Bee Smears Jan 23 '15 at 20:30
  • you're right it doesn't (at least not in python). you're working in Java, so I don't know your answer, but I know that `sendkeys()` will not work for every field. sometimes you have to execute some javascript before you can send information. often times, though, I find that the problem's in my code -- i.e., I'm not accessing the element correctly b/c it's in an `iframe` or something. – Bee Smears Jan 23 '15 at 20:35
  • I would re post your question with more information (what you've tried, what you're trying to do, and code so SO users can test it), and tag the question as `java,` so more people see it. – Bee Smears Jan 23 '15 at 20:36