- 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.
@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.
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.