Reputation: 21
<ul class="popupmenu is-open" id="menuFormDefaultFC" role="menu" aria-hidden="false">
<li role="presentation"><a tabindex="-1" role="menuitem" href="#A">Add</a>
Please somebody let me know the Xpath for above html with href in it.
Upvotes: 0
Views: 138
Reputation: 513
Use Firefox plugin "Firepath" to extract xpath.
https://addons.mozilla.org/en-US/firefox/addon/firepath/
Upvotes: 0
Reputation: 14289
Here are a few options for href.
1. By.xpath(".//a[@href='#A']");
2. By.xpath(".//li[@role='presentation']/a[@href='#A']");
But for links you could use just linkText
. I prefer below for simplicity unless your app supports multiple locales.
By.linkText("Add");
Or use CSS selectors
1. By.cssSelector("a[role='presentation']");
2. By.cssSelector("li[role='presentation']>a[href='#A']");
Upvotes: 1
Reputation: 29669
I would do it this way:
By closedMenu = By.xpath(".//ul[not(contains(@class, 'is-open'))]");
By openMenu = By.xpath(".//ul[contains(@class, 'is-open')]");
By addItem = By.linkText("Add");
By addItemLocator = new ByChained(openMenu, addItem);
Upvotes: 0
Reputation: 4264
Try this //a[contains(text(),'Add')]
It may be used as driver.find_element_by_xpath("//a[contains(text(),'Add')]")
Upvotes: 0