0

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();
YaDav MaNish
  • 1,260
  • 2
  • 12
  • 20
  • Use Selenide to add dynamic waits easily. https://selenide.org/documentation/selenide-vs-selenium.html – Aruna Aug 03 '21 at 23:35

2 Answers2

1

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 !");
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

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()

Prophet
  • 32,350
  • 22
  • 54
  • 79