2

I tried everything from alerts to multiple window handlers but not able to get rid of the popup come when we load below site on initial stage.

https://www.build.com/

Can you please help me on this to just get to above URL and handle the pop up, want to close it straight away.

Thanks Ankit

2 Answers2

1

The pop up you are referring to is not exactly a "Pop Up" window. Its just an element loading in the same page. So, wait till that element appears in the page and click the close button.

# in Java
driver.findElement(By.xpath("//*[@class='close-icon']")).click();

# or in JavaScript
document.querySelector('.close-icon').click();

To wait for any particular element, check this answer

Naveen
  • 610
  • 11
  • 21
1

The desired element is within a Modal Dialog Box so to locate/click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

Solution

You need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.close.js-modal-close. > span.close-icon"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='close js-modal-close ']/span[@class='close-icon']"))).click()
    
  • Note : You have to add the following imports:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • Thank You, But I tried the simple explicit wait and cllick on close button to achieve the same. – Ankit Prajapati Feb 27 '20 at 12:58
  • @AnkitPrajapati Inducing _WebDriverWait_ for `element_to_be_clickable()` is part of the best practices while invoking `click()`. You can't avoid it when dealing with Javascript based elements. – DebanjanB Feb 27 '20 at 13:04