首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何关闭selenium中弹出的Shopee

如何关闭selenium中弹出的Shopee
EN

Stack Overflow用户
提问于 2022-03-28 08:12:35
回答 1查看 250关注 0票数 1

我想关闭硒网站https://shopee.com.my/的弹出窗口,请检查下面的图像。

我试过在下面,但是有错误,比如

代码语言:javascript
复制
NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":".shopee-popup__close-btn"}

代码:

代码语言:javascript
复制
driver.find_element_by_class_name("shopee-popup__close-btn").click()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-28 10:08:32

它在树根上。

代码:

代码语言:javascript
复制
driver_path = r'C:\\Users\\***\\***\\chromedriver.exe'

driver = webdriver.Chrome(driver_path)

driver.maximize_window()
wait = WebDriverWait(driver, 30)

driver.get("https://shopee.com.my/")

wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='English']"))).click()

try:
   time.sleep(3)
   close_btn = driver.execute_script('return document.querySelector("#main shopee-banner-popup-stateful").shadowRoot.querySelector("div.home-popup__close-area div.shopee-popup__close-btn")')
   close_btn.click()
   print('Clicked successfully')
except:
   print('Could not clicked')
   pass

导入:

代码语言:javascript
复制
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71644252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档