-2

I have element newdevice, with the following attribute remove device from account.

newdevice is unique, but a lot of same attributes.

enter image description here

Problem that I unable to perform click button.

WebElement newdevice = driver.findElement(By.linkText(devicename));
        if (newdevice.isDisplayed() && newdevice.isEnabled()) {
            newdevice.getAttribute("remove device from account");
            Thread.sleep(3000);
            newdevice.click();
        }

So I expecting to find new element, if element is presence, then find attribute bellow element and click on it.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • 2
    Welcome to SO. Please take the time to read [ask]. It will help you craft solid questions that will hopefully get useful answers. Also, edit your question to include the HTML instead of posting as a screenshot. – orde Sep 16 '19 at 16:17

1 Answers1

0

To click() on the element with text as remove device from account within the element newdevice you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • xpath 1:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td/strong[text()='newdevice']//following::td[3]//button[contains(@title, 'remove device')]"))).click();
    
  • xpath 2:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td/strong[text()='newdevice']//following::td//button[@title='remove device from account']"))).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217