0

I am trying to click on the button Edit button from drop-down list using WebdriverIO:

enter image description here

Inspecting the dropdown element yields the following HTML structure:

enter image description here

Currently using this approach:

driver.findElement(By.xpath("//*[text()[contains(., '"+"Edit"+"')]]" )).click();

Unfortunately it's not woring. How should I proceed to make it work?

iamdanchiv
  • 4,052
  • 4
  • 37
  • 42
  • 1
    It is recommended to add the html source code instead of image and add the exceptions/errors you encounter while the trials you do. – Sooraj Dec 24 '19 at 13:17
  • Daniel, you are using [WebdriverIO](https://webdriver.io/) framework for this? If so, the answers below, as well as your approach resemble the Java/C# ecosystems. If it is indeed a WDIO question, I'll add an answer. – iamdanchiv Jan 04 '20 at 08:52

2 Answers2

1

To click on the element you can use either of the following Locator Strategies:

  • xpath 1:

    driver.findElement(By.xpath("//a[@class='dropdown-item' and contains(., 'Edit')]" )).click();
    
  • xpath 2:

    driver.findElement(By.xpath("//a[@class='dropdown-item' and normalize-space()='Edit']" )).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try using normalize-space function in Xpath:

//a[normalize-space(text())='Edit']

Sooraj
  • 565
  • 3
  • 8