bik_code
bik_code

Reputation: 13

Object inside inner html not getting identified by selenium web driver

I want to select and click on the object present inside inner html (shown in the image). But the object is not getting identified. I am using Java.

Note --> my application not opening with any browser except Internet Explorer and I can't verify xpath from console/debugger so I have to verify it through code only.

Code I have tried so far but not working for me-->

option 1 -->

driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a href[@text='Administrate']")).click();

option 2 -->

driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a[@text='Administrate']")).click();

option 3 -->

driver.findElement(By.xpath("/html/frameset/frame[1]/html/body/ul/li/ul/li[1]")).click();

I have pasted the html structure here

Upvotes: 1

Views: 461

Answers (2)

NarendraR
NarendraR

Reputation: 7708

You need to change your XPath like

driver.switchTo().frame("nav");
driver.findElement(By.xpath("//a[text()='Administrate system']")).click();

Note:- Here you need to pass complete string for better learning please refer Firepath to create and evaluate your xpath

Also can use contains method to find an element on partial text basis

Upvotes: 0

Guy
Guy

Reputation: 50899

You are checking for exact text match, use contains instead

driver.findElement(By.xpath("//a[contains(text(), 'Administrate')]")).click();

Or

driver.findElement(By.xpath("//a[contains(., 'Administrate')]")).click();

Please note the difference between text() and @text

Upvotes: 1

Related Questions