要根据用户使用Selenium和python的输入来定位元素,您需要为引入WebDriverWait,
visibility_of_element_located()并且您可以使用以下两种定位器策略之一:
- 在中使用变量
XPATH
:
user_input = '23456' element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@]//div/p[@ and text()='" +user_input+ "']")))
%s
在中使用XPATH
:
user_input = '23456' element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@]//div/p[@ and text()='%s']"% str(user_input))))
format()
在中使用XPATH
:
user_input = '23456' element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@]//div/p[@ and text()='{}']".format(str(user_input)))))
- 注意 :您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)