英文:
Selenium Python: How to close the overlay by clicking on the svg element
问题
我正在寻找一种点击SVG叉叉以关闭叠加的欢迎窗口的方法。我已成功完成登录和授权,但这个叉叉让我发疯。
代码尝试:
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']")))
错误信息: TimeoutException: Message:
HTML快照:
另一个HTML快照:
英文:
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:
Another snapshot of the HTML:
答案1
得分: 1
X`_ 图标,您需要使用 WebDriverWait 来等待 element_to_be_clickable(),并且您可以使用以下任一 定位策略:
-
使用 CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "h2 svg.jss109[viewBox]"))).click()
-
使用 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()
-
注意:您需要添加以下导入项:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论