Python Selenium不会加载链接文本-我缺少什么
尝试让Selenium在访问注册表单之前单击cookie策略按钮上的Accept。(我想自动实现等待名单功能,因为在这个健身房里,等待名单总是一场比赛)但我在第一个关卡上被卡住了,花了几个小时试图消除错误信息。你能帮忙吗 代码 错误消息:Python Selenium不会加载链接文本-我缺少什么,python,selenium,Python,Selenium,尝试让Selenium在访问注册表单之前单击cookie策略按钮上的Accept。(我想自动实现等待名单功能,因为在这个健身房里,等待名单总是一场比赛)但我在第一个关卡上被卡住了,花了几个小时试图消除错误信息。你能帮忙吗 代码 错误消息: Traceback (most recent call last): File "C:\Users\Csongor\Dropbox\Coding\new test 6th oct 2020\test.py", line 8, in &l
Traceback (most recent call last):
File "C:\Users\Csongor\Dropbox\Coding\new test 6th oct 2020\test.py", line 8, in <module>
driver.get("https://member.superfit.club/").find_element_by_link_text("Akzeptieren").click()
AttributeError: 'NoneType' object has no attribute 'find_element_by_link_text'
回溯(最近一次呼叫最后一次):
文件“C:\Users\Csongor\Dropbox\Coding\new test 6th oct 2020\test.py”,第8行,在
驱动程序。获取(“https://member.superfit.club/)。通过链接文本(“Akzeptieren”)查找元素。单击()
AttributeError:“非类型”对象没有属性“通过链接查找元素”
显示的代码不反映错误堆栈跟踪中的内容。显然,您是这样调用find\u element\u by\u link\u text
:
driver.get(“https://member.superfit.club/)。通过链接文本(“Akzeptieren”)查找元素。单击()
当你应该按照你展示的那样做时:
driver.get(“https://member.superfit.club/")
驱动程序。通过链接文本(“Akzeptieren”)查找元素。单击()
显示的代码不反映错误堆栈跟踪中的内容。显然,您是这样调用find\u element\u by\u link\u text
:
driver.get(“https://member.superfit.club/)。通过链接文本(“Akzeptieren”)查找元素。单击()
当你应该按照你展示的那样做时:
driver.get(“https://member.superfit.club/")
驱动程序。通过链接文本(“Akzeptieren”)查找元素。单击()
为什么不直接使用xpath
而不是链接文本
driver.find_element_by_xpath('//*[@id="CookieModelButtom"]/div/div/div/div/button[1]').click()
这个很好用。我建议您使用xpath
或CSS选择器
而不是链接文本
为什么不直接使用xpath
而不是链接文本
driver.find_element_by_xpath('//*[@id="CookieModelButtom"]/div/div/div/div/button[1]').click()
这个很好用。我建议您使用xpaths
或CSS选择器
而不是链接文本
您可以通过文本值找到按钮
请尝试以下代码:
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://member.superfit.club/")
#driver.find_element_by_link_text("Akzeptieren").click()
driver.find_element_by_xpath('//button[contains(text(), "Akzeptieren")]').click()
您可以通过文本值找到按钮
请尝试以下代码:
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://member.superfit.club/")
#driver.find_element_by_link_text("Akzeptieren").click()
driver.find_element_by_xpath('//button[contains(text(), "Akzeptieren")]').click()
find_element_by_link_text
()适用于锚元素而不是按钮元素。您正在与之交互的元素是按钮,因此您可以标识ID、名称、XPATH或CSS选择器
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-success"))).click()
我建议您使用WebDriverWait()
和元素可点击()并使用以下css选择器
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-success"))).click()
您需要导入以下库
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
find_element_by_link_text
()适用于锚元素而不是按钮元素。您正在与之交互的元素是按钮,因此您可以标识ID、名称、XPATH或CSS选择器
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-success"))).click()
我建议您使用WebDriverWait()
和元素可点击()并使用以下css选择器
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-success"))).click()
您需要导入以下库
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
太好了,谢谢!你知道当我的Gmail收到一封特定的电子邮件时,有什么巧妙的方法来运行这个脚本吗?对于Gmail,你可以尝试使用Gmail API或使用IMAP模块进行连接。检查以下页面:API:IMAP:非常好,谢谢!你知道当我的Gmail收到一封特定的电子邮件时,有什么巧妙的方法来运行这个脚本吗?对于Gmail,你可以尝试使用Gmail API或使用IMAP模块进行连接。检查以下页面:API:IMAP:非常好,谢谢!你知道当我的Gmail收到一封特定的电子邮件时,有什么巧妙的方法来运行这个脚本吗?太好了,谢谢!你知道当我的Gmail收到一封特定的电子邮件时,有什么巧妙的方法来运行这个脚本吗?太好了,谢谢!你知道当我的Gmail收到一封特定的电子邮件时,有什么巧妙的方法来运行这个脚本吗?太好了,谢谢!当一封特定的电子邮件进入我的Gmail时,你知道有什么巧妙的方法来运行这个脚本吗?