答案 0 :(得分:2)
假设'placeholder =“Search”'位始终相同,那么您可以这样做:
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
driver = webdriver.Firefox()
driver.get("http://www.python.org")
searchbox = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(
(By.XPATH, "//input[@placeholder='Search']")
)
)
根据在字段上设置的属性,通过XPATH获取elemt。