【发布时间】:2020-09-13 23:20:41
【问题描述】:
我是 selenium Python 的新手,并且一直在使用一些网站练习这些概念。我被以下问题困住了。
-
当我打开这个网站 (https://www.shoppersstop.com/) 并点击品牌时,我会弹出一个 cookie:
We use cookies to give you the best experience and analyze the site use. By continuing your browsing, you accept their use. Find out more about cookies in Privacy Policy.
任何人都可以帮助我如何关闭这个弹出窗口,虽然它没有警报?
- 当我将鼠标悬停在 hautecurry 上时,只有我可以看到必须单击的“立即查看”按钮。谁能帮我解决这个问题?
以下是我目前尝试过的代码:
-
关闭 cookie 弹出窗口:
wait = WebDriverWait(driver, 10) wait.until(expected_conditions.presence_of_element_located((By.CLASS_NAME, "closecookieExitButton"))) driver.find_element_by_class_name("close cookieExitButton").click()
我使用了定位元素的存在,也是可点击的元素,但它没有被关闭。
-
点击仅在鼠标悬停时可见的“立即查看”按钮:
action = ActionChains(driver) viewNow = driver.find_element_by_xpath("//a[@href='/haute-curry']/span") action.move_to_element(viewNow).perform() viewNow.click()
尽管我的自定义 xpath 是唯一的,但它不会引发任何元素发现异常。
【问题讨论】:
-
请在块中编写代码以更好地理解您的问题。
-
请edit the question 将其限制为具有足够详细信息的特定问题,以确定适当的答案。避免一次问多个不同的问题。请参阅How to Ask 页面以获得澄清此问题的帮助。
标签: python selenium xpath css-selectors webdriverwait