Manish Rai
Manish Rai

Reputation: 1

I am not able to close the first pop up appearing on the website when I land on the website (https://www.seleniumeasy.com/test/)

I'm new to automation and trying to run my code but when I land on the page the first pop up appearing doesn't allow me to process as I'm not able to close this pop-up.

System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver_win32\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    
    driver.get("https://www.seleniumeasy.com/test/");
    
    driver.findElement(By.xpath("//*[@id='at-cv-lightbox-close']")).click();

Upvotes: 0

Views: 137

Answers (2)

cruisepandey
cruisepandey

Reputation: 29362

You can use the below id with Explicit wait : (None of the answer actually provide solution with ID, when we all know that ID is always preferable than a xpath)

ID

at-cv-lightbox-close

Code :

System.setProperty("webdriver.chrome.driver", "C:\Users\chromedriver_win32\chromedriver.exe"); 
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.seleniumeasy.com/test/");
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.id("at-cv-lightbox-close"))).click();
System.out.println("Task has been done !");

Upvotes: 1

Prophet
Prophet

Reputation: 33361

You need to add a wait before accessing that element.
Like this:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 20)

wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='at-cv-lightbox-close']"))).click()

Upvotes: 0

Related Questions