python - 硒与python如何点击弹出按钮
问题描述
我已经尝试了许多可能的情况,但我无法访问它请帮助我解决这个问题,我如何点击 common-home res layout-home1 加载的隐藏滚动模态 - 在此处打开我想点击(添加到购物车)和(愿望清单)我的代码如下
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
from time import sleep
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import ElementNotVisibleException
driver = webdriver.Chrome(executable_path='C:\Program Files\JetBrains\PyCharm 2021.1.1/chromedriver.exe')
driver.maximize_window()
driver.get("http://esindbaad.com/")
#mouse hour to catagories
beauty = driver.find_element_by_xpath("//*[@id='head-wrapper']/div/div/div/div/ul/li[3]/a")
body = driver.find_element_by_xpath("//*[@id='head-wrapper']/div/div/div/div/ul/li[3]/div/div/div/div/div/div[1]/div[3]/div/ul/li[6]/a")
actions = ActionChains(driver)
actions.move_to_element(beauty).move_to_element(body).click().perform()
#add to wishlist
wish = driver.find_element_by_xpath("//*[@id='content']/div/div[1]/div[1]/div/div[1]/div/button[1]/i")
actions = ActionChains(driver)
actions.move_to_element(wish).click().perform()
#click and view product
product = driver.find_element_by_xpath("//*[@id='content']/div/div[1]/div[1]/div/div[1]/div/a")
actions = ActionChains(driver)
actions.move_to_element(product).click().perform()
# product added to cart button click
driver.switch_to.frame(iframe)
addcart = driver.find_element_by_id("button-cart")
actions = ActionChains(driver)
actions.move_to_element(addcart).click().perform()
wishlist = driver.find_element_by_xpath("//*[@id='product']/div[2]/div[3]/ul/li/a")
actions = ActionChains(driver)
actions.move_to_element(wishlist).click().perform()
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
解决方案
等待窗口出现,然后使用显式等待单击它
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
addcart = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "button-cart")))
推荐阅读
- javascript - 在项目构建之后(通过 Ionic build 命令),当我点击我的 ionic react 项目的 index.html 文件时出现错误
- flutter - 如何防止在 Flutter 的 InheritedWidget 中重新创建小部件?
- python - Pandas 对 Numpy 不同的 dtype 数组进行投射
- java - 从一个类返回到另一个类的方法
- javascript - 文本颜色在 CSS 中悬停时不会改变
- python - Python YellowBrick Rank1d 标签/功能名称截止
- swift - 窗口根更改后的 TabBar 可见性问题
- reactjs - 解析错误:“parserOptions.project”已为@typescript-eslint/parser 设置。该文件与您的项目配置不匹配:jest.config.js
- ubuntu - 我无法在 ubuntu 服务器上安装 discord.py(数字海洋)
- zebra-printers - Zebra ZPL 切断尾随而不是环绕