John Wick
John Wick

Reputation: 23

Not able to locate element in Selenium tried xpath,name,id,css selector

I have tried using the name, id, xpath. However I get the same error in Eclipse that it is not able to locate the element.

WebDriver driver=new FirefoxDriver();  
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://accenturenordicspov.service-now.com/navpage.do");
driver.findElement(By.xpath("/html/body/form/table/tbody/tr[3]/td[2]/input")).sendKeys("John");
driver.findElement(By.xpath("/html/body/form/table/tbody/tr[4]/td[2]/input[1]")).sendKeys("A***");
driver.findElement(By.id("/html/body/form/table/tbody/tr[7]/td[2]/button")).click();

Upvotes: 1

Views: 1223

Answers (3)

John Wick
John Wick

Reputation: 23

It first needs to move to that frame and then input the elements. Above code will work if just put this piece of code before inputting the elements:

String x="gsft_main";
driver.switchTo().frame(x);

Upvotes: 0

JRodDynamite
JRodDynamite

Reputation: 12613

According to the link you've given, the form is in an iframe. Hence, you need to switch to the frame and then fill the form. You should try this:

driver.switch_to.frame("gsft_main")
driver.findElement(By.xpath("//input[@id='user_name']").sendKeys("John");
driver.findElement(By.xpath("//input[@id='user_password']").sendKeys("A***");
driver.findElement(By.xpath("//button[@id='sysverb_login']").click();

Upvotes: 3

dinesh
dinesh

Reputation: 48

May be in different frame. Kindly check for the frame or iframe tag is parent of the box you are going to interact. If yeas then You have to switch to that frame then only You can interact.

Upvotes: 2

Related Questions