0

I'm using Selenium for my autotests but got stack with XPATH.

I need to delete user and groups from address book but I do not understand which locator i need to use I was trying using different Xpaths, but maybe you can tell me what to read because now I' totally lost.

HTML of the addressbook:

Here is addressbook

What I've tried

driver.findElement(By.xpath("//form[@lastname='Anna']/input")).click();

and

//table[@id='maintable']/tbody/tr[12]/td[2]
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Amo Ra
  • 5
  • 3
  • 1
    Please update the question with text based HTML to received effective solution form other contributor. – KunduK Dec 16 '20 at 10:59

2 Answers2

0

To click() on the with for user Anna you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("input[title*='Anna'][alt*='Anna'][type='checkbox']")).click();
    
  • xpath:

    driver.findElement(By.xpath("//input[contains(@title, 'Anna') and contains(@alt, 'Anna')][@type='checkbox']")).click();
    

Ideally to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[title*='Anna'][alt*='Anna'][type='checkbox']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[contains(@title, 'Anna') and contains(@alt, 'Anna')][@type='checkbox']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

Your XPath fetch first input child of form node which is hidden. Try more specific selector

"//input[@title='Select (testuser Anna)']"
JaSON
  • 4,843
  • 2
  • 8
  • 15