I want to find an element which is visible by mouse hover and I need to click on it and it then opens a text field. When I give the XPath for the element in fire-path, it detects 6 instances of the element. I need the first element. I'm using Java and when I try to run the script it gives me error about unable to locate the element
use getattribute function in the webdriver with the Xpath then you will get that specific instance of the element
Boolean b= driver.findbyelement(by.xpath("")).getattribute('transparent');
Check b is true or false if it true then you are select the correct instance
Or you can use the css as well
Xpath offers a way to select the Nth matching element of your expression by giving:
Although this is going to select all the Nth
children elements of matching nodes to your expression. So, it will return many results in your case also.
But there is a solution. In order to achieve a
global selection of the Nth matching element you need to wrap your expression in parantheses:
So, in your case it would be (note the wrapping parantheses):
(//i[@title='Rename' and ng-click='editCampaignName($index)'])
Let us know if it worked for you.
I think u can use Actions if u are trying to find an element in a tooltip.For example
Actions tooltip = new Actions(driver); tooltip.moveToElement(driver.findElement(By.xpath("The xpath that u want to move your mouse there")).build.perform(); //After this, U can then try to get the element in that tooltip
Find the xpath of the element from browser
- select the element under which this hidden element is expected to appear.
- Right click and select Force state --> ':hover'
This will expose the element. Get its xpath.
On Selenium-webdriver use moveToElement(<parent_element>).perform() and locate the required element using the xpath previously found