I have opened this site https://www.seleniumeasy.com/test/basic-first-form-demo.html
as I open there is popup showing
How to go on that popup & click on close using selenium?
I have opened this site https://www.seleniumeasy.com/test/basic-first-form-demo.html
as I open there is popup showing
How to go on that popup & click on close using selenium?
Use below code. These are some chances that you are not using proper wait and XPath.
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\src\\test\\resources\\executables\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='at-cv-lightbox-close']")));
driver.findElement(By.xpath("//*[@id='at-cv-lightbox-close']"));
driver.quit();
To click and close the popup you need to induce WebDriverWait for the elementToBeClickable()
and you can use either of the following Locator Strategies:
cssSelector
:
new WebDriverWait(webDriver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[title='Close']"))).click();
xpath
:
new WebDriverWait(webDriver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@title='Close']"))).click();