• I need to click on an element which is inside the div tag. I tried using the xpath which when used detects the element both in the console and in the Katalon ide.
  • But when the script is run, it doesn't detect the element as the path given doesn't exactly point to the cancel icon I need to click.
  • I have attached a screenshot highlighting the element and its attribute. enter image description here
  • can't you target by the close class?
    – Adelin
    Commented Feb 16, 2018 at 13:11
  • @Adelin It doesn't catch the close icon even if I give that as the attribute. Gave all the types of attributes. Still it can't perform any actions on that icon Commented Feb 16, 2018 at 13:22
  • What's the exact code you used, for both the xpath and the close class?
    – Adelin
    Commented Feb 16, 2018 at 13:24
  • @FindBy(css = "div.close") WebElement CloseButton; WebDriverWait wait = new WebDriverWait(driver,30); wait.until(ExpectedConditions.visibilityOf(CloseButton)); Actions action = new Actions(driver); action.moveToElement(CloseButton).build().perform(); CloseButton.click(); Commented Feb 16, 2018 at 14:09

2 Answers 2

     @FindBy(xpath = "//*[@class='prompt']/..")
     WebElement choiceHeader;
     WebDriverWait wait = new WebDriverWait(driver,30);
     Integer parentWidth = choiceHeader.getSize().width;
     Actions ac = new Actions(driver);
    ac.moveToElement(choiceHeader, parentWidth-13, 13).click().build().perform();
  • This does find the element and then scroll to the position and click on the element which was highlighted in the screenshot.

You can try this:

@FindBy(css = "#demo_page1 .close")
WebElement CloseButton;
PageFactory.initElements(driver, this);
WebDriverWait wait = new WebDriverWait(driver,30); 
Actions action = new Actions(driver);

And also take a look at this link.

  • The mentioned answer doesn't work. It gives the same error as previous. I found a solution which does work without any issues. Commented Feb 19, 2018 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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