0
  • 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 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 Feb 16 '18 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 – K.K Feb 16 '18 at 13:22
  • What's the exact code you used, for both the xpath and the close class? – Adelin Feb 16 '18 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(); – K.K Feb 16 '18 at 14:09
2
     @FindBy(xpath = "//*[@class='prompt']/..")
     WebElement choiceHeader;
     WebDriverWait wait = new WebDriverWait(driver,30);
     wait.until(ExpectedConditions.visibilityOf(choiceHeader));
     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.
0

You can try this:

@FindBy(css = "#demo_page1 .close")
WebElement CloseButton;
PageFactory.initElements(driver, this);
WebDriverWait wait = new WebDriverWait(driver,30); 
wait.until(ExpectedConditions.elementToBeClickable(CloseButton));
Actions action = new Actions(driver);
Thread.sleep(3000);
action.moveToElement(CloseButton).build().perform();
CloseButton.click();

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. – K.K Feb 19 '18 at 9:34

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.