我尝试使用find_element_by_class_name和link text,这两种方法都会导致nosuchement异常。我只是想为https://v2.waitwhile.com/l/fostersbarbershop/list-view点击这个加入等待列表按钮-非常感谢您的帮助
from selenium import webdriver
import time
PATH = "C:\Python\Pycharm\attempt\Drivers\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://v2.waitwhile.com/l/fostersbarbershop/list-view")
join = False
while not join:
try:
joinButton = driver.find_element_by_class_name("disabled")
print("Button isnt ready yet.")
time.sleep(2)
driver.refresh()
except:
joinButton = driver.find_element_by_class_name("public-submit-btn")
print("Join")
joinButton.click()
join = True
似乎您有同步问题
诱导
WebDriverWait()
并等待element_to_be_clickable()
查找以下ID定位器您需要导入以下库
浏览器快照
您尝试自动化的页面是有角度的。通常,在基于脚本的页面中,您下载源代码,页面加载事件被归类为完成,然后运行一些JS脚本来获取/更新页面内容。这些脚本(可能需要几秒钟才能完成)使用您看到的页面更新DOM
相反,selenium只能识别页面是否已加载-selenium将尝试在此readystate点查找这些元素,并且不知道任何正在运行的脚本
在继续之前,您需要等待元素准备就绪
简单的解决方案是在脚本中添加隐式等待。 隐式等待将忽略NoTouchElement异常,直到达到超时
有关等待的更多信息,请参见here
这是要添加的代码行:
只要根据需要调整时间就行了
你只需要一次
这是适用于我的代码:
这是最终状态:
相关问题 更多 >
编程相关推荐