python - Selenium Python 点击只有一半的时间
问题描述
但我正在尝试为我的网站编写一个单元测试,该测试贯穿所有链接并在网站正常运行时返回 A ok 或 no go。但是我遇到了无法不断单击站点导航栏中的链接的程序的问题。我已经尝试过多次隐式等待。明确的,预期的条件,但页面加载和一半的时间将单击链接并转到站点的该部分,而另一半程序只是停止并且没有单击任何内容。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
PATH = "C:\Program Files (x86)\chromedriver.exe"
drive = webdriver.Chrome(PATH)
drive.get("https://www.blackhempfamily.com/")
wait = WebDriverWait(drive, 10)
link = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Why Black Hemp?")))
link.click()
解决方案
将是一个更好的标签使用。
wait.until(EC.element_to_be_clickable((By.XPATH, "//p[text()='Why Black Hemp?']")))
推荐阅读
- sql - SQL 文本搜索速度
- python-3.x - 如何编写一个函数,反向打印 data.txt 中的行
- vue.js - 刷新 gin-gonic 中的静态文件
- python - 当识别类别从 11 增加到 17 时,卷积神经网络返回 Value Error。喀拉斯
- http - 为什么 HTTP 协议规定 GET 和 HEAD 方法不应该具有采取检索以外的操作的意义?
- junit5 - JUnit5 不同参数的多个来源(笛卡尔积)
- sharepoint-2013 - 为什么在 SharePoint 自定义网站设计中未加载预览图像?
- javascript - Bootstrap 4 警报使用 cookie 永久关闭
- angular - TypeScript service.ts 连接 Postgresql 数据库
- python - discord.py 使用 `with sqlite3.connection` 是个坏主意?