什么是WebDriverWait(Driver,20)'意思是?
我正在处理以下硒代码:
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
PATH= r"C:\Users\Hamid\Desktop\Selenium\chromedriver.exe"
driver=webdriver.Chrome(PATH)
driver.get("https://www.google.com/")
click_button=driver.find_element_by_xpath('//*[@id="L2AGLb"]/div').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("ONS data")
search=driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div[1]/div[1]/div[3]/center/input[1]').click()
我不确定以下代码的分解是什么:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("ONS data")
WebDriverWait是什么意思? 20指的是什么? EC元素是什么意思?为什么需要等待? Q指的是什么?
如果我想使用相同的代码在页面上的其他项目上使用,我通常会更改什么?
I am working with the following Selenium code:
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
PATH= r"C:\Users\Hamid\Desktop\Selenium\chromedriver.exe"
driver=webdriver.Chrome(PATH)
driver.get("https://www.google.com/")
click_button=driver.find_element_by_xpath('//*[@id="L2AGLb"]/div').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("ONS data")
search=driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div[1]/div[1]/div[3]/center/input[1]').click()
I am not sure however what the breakdown for the following line of code is:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("ONS data")
What does WebDriverWait mean? What does 20 refer to? What is meant by the EC element? Why does one need to wait? What does q refer to?
If I wanted to use this same code to work on a different item on the page, what would I typically change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 webdriverwait 构造函数将Web驱动程序的实例和超时以几秒钟作为参数。
例如,使用强制性参数:
使用 lambda 表达式:
使用所有参数:
As per the API documentation of WebDriverWait the constructor takes a WebDriver instance and timeout in seconds as arguments.
As an example, using the mandatory arguments:
Using lambda expression:
Using all the arguments: