Reputation: 23
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.
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
Upvotes: 2
Views: 759
Reputation: 193088
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:
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
Upvotes: 1
Reputation: 788
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
Upvotes: 1