Python Selenium无法正确确定页面是否有<;标题>;html标签
我试图让Selenium在加载Python时等待网页的标题标记出现 我尝试过用其他类型的HTML标记测试这段代码,只有Python Selenium无法正确确定页面是否有<;标题>;html标签,python,selenium,selenium-webdriver,webdriverwait,page-title,Python,Selenium,Selenium Webdriver,Webdriverwait,Page Title,我试图让Selenium在加载Python时等待网页的标题标记出现 我尝试过用其他类型的HTML标记测试这段代码,只有标记没有导致错误 wait = WebDriverWait(driver, 10) driver.get(link) wait.until(EC.visibility_of_element_located((By.TAG_NAME, 'div'))) 我期望代码评估完成,但我得到以下错误: Traceback (most recent call last): File "&
标记没有导致错误
wait = WebDriverWait(driver, 10)
driver.get(link)
wait.until(EC.visibility_of_element_located((By.TAG_NAME, 'div')))
我期望代码评估完成,但我得到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/usr/lib/python3.7/site packages/selenium/webdriver/support/wait.py”,第80行,直到
引发TimeoutException(消息、屏幕、堆栈跟踪)
selenium.common.Exception.TimeoutException:消息:
标题标签永远不可见。但是,您可以等待它的出现:
标题也有自己的预期条件,title\u是()
和title\u包含()
。例如:
wait.until(EC.title_is("Google"))
您可以在中查看受支持的预期条件的完整列表。标签
永远不可见。但是,您可以等待它的出现:
标题也有自己的预期条件,title\u是()
和title\u包含()
。例如:
wait.until(EC.title_is("Google"))
如果要访问页面标题,可以查看中支持的预期条件的完整列表。,找到
标记不是理想的方法
要打印标题,您需要针对以下任一预期条件诱导WebDriverWait:
- 例如:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
WebDriverWait(driver, 10).until(EC.title_contains("G"))
print("Page title is: %s" %(driver.title))
- 控制台输出:
Page title is: Google
如果要访问页面标题,定位
标记不是理想的方式
要打印标题,您需要针对以下任一预期条件诱导WebDriverWait:
- 例如:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
WebDriverWait(driver, 10).until(EC.title_contains("G"))
print("Page title is: %s" %(driver.title))
- 控制台输出:
Page title is: Google
该页面是否有div
元素?该页面是否有div
元素?哇,非常感谢您的帮助!这绝对是一个令人头痛的问题;我应该更加注意方法名称的实际含义。哇,非常感谢你的帮助!这绝对是一个令人头痛的问题;我应该更加注意方法名称的实际含义。