Home > Software design >  Selenium Python: How to close the overlay by clicking on the svg element
Selenium Python: How to close the overlay by clicking on the svg element

Time:02-06

I am looking for a way to click on the svg cross to close overlaying welcome window. I managed to go through login and authorization but this cross is getting me crazy.

Code trials:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "jss109"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//svg[@class='jss109']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'svg[aria-hidden="True"]')).click()
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CLASS_NAME, "JSS109"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@class='jss109']/*[name()='svg']")))

Error massage: TimeoutException: Message:

Snapshot of the HTML:

enter image description here

Another snapshot of the HTML:

enter image description here

CodePudding user response:

To click on the X icon you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "h2 svg.jss109[viewBox]"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[.//span[starts-with(., 'Welcome to new')]]//*[name()='svg' and @class][@viewBox]"))).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
    
  • Related