0

Can anyone help me in writing xPath for below image, I wrote one but it's not working.

enter image description here

My xPath is //li[@class='active']//a[@class='dropdown-button btn']

  • Add some more HTML code, starting from descent node (div) – Bharat Mane Jun 4 '18 at 16:07
1

If you don't mind switching to CSS selectors, use the following:

CSS selector: #nav-mobile .active a.dropdown-button.btn

0
//ul[@id="dropdown1"]/preceding-sibling::a

Try with the above XPath.

0

Try using below XPath:

//a[@class='dropdown-button btn'];
  • Thanks For Comment Prasanna, i Tried That To Now its Not Working. – koushick Jun 4 '18 at 12:48
  • Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class='dropdown-button btn']"} – koushick Jun 4 '18 at 12:48
  • Are you sure you're within the right context? Is the element maybe part of an iframe? Because the xpath is valid and should match, given that the element exists in your current context and at the time you call it. – Daniel Jun 4 '18 at 12:51
  • i Used This Code Only – koushick Jun 4 '18 at 12:57
  • WebElement e4=driver.findElement(By.xpath("//a[@class='dropdown-button btn']")); Actions a1=new Actions(driver); a1.moveToElement(e4).click().build().perform(); – koushick Jun 4 '18 at 12:57
0

Try below Xpath and share your feedback

//*[contains(@class,'active')]/descendant::a[@class='dropdown-button btn']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.