Why does my locator isn't working together?

30 Views Asked by At

These two lines are working independently. If I commented one and run it works. But it is not working together.

line1:driver.findElement(By.id("MemberNo")).sendKeys("1");

line2:driver.findElement(By.xpath("//*[@id=\"VoucherNo\"]")).sendKeys("20201001");

Getting no Exception. UI Scenario:enter image description here

Advise and suggestions as I am new to selenium java.

1

There are 1 best solutions below

0
Maruthi Sikhakolli On

Things you can try:

  • Check if the xpath is proper. Since you said its working independently, I assume its correct.
  • Generally if we use double quotes everywhere you may get into issue. Try using the combination of single or double quotes. For the second xpath you may try something like driver.findElement(By.xpath("//*[@id='VoucherNo']")).sendKeys("20201001");
  • Sometimes there needs to be some time gap required while working on multiple elements in the same form. Try putting a wait condition between those two statements and execute.

Since both of the lines are performing action on different UI elements and as they are working independently, I don't see a possible scenario of why they wont work combinely.