Python Selenium按名称查找元素
我正在使用Python Selenium,并试图在输入框中选择没有ID的Python Selenium按名称查找元素,python,selenium,selenium-webdriver,ui-automation,webautomation,Python,Selenium,Selenium Webdriver,Ui Automation,Webautomation,我正在使用Python Selenium,并试图在输入框中选择没有ID的 <div class="form-group"><input type="email" class="form-control" name="quantity" placeholder="Type a quantity"></div> inputElement = driver.find_element_by_id("quantity") inputElement=驱动程序。按\u
<div class="form-group"><input type="email" class="form-control" name="quantity" placeholder="Type a quantity"></div>
inputElement = driver.find_element_by_id("quantity")
inputElement=驱动程序。按\u id(“数量”)查找\u元素
按名称选择此元素的最佳方法是什么?方法适用于此:
driver.find_element_by_name("quantity")
我多次使用此方法从元素中收集属性:
for i in browser.find_elements_by_class_name("form-control"):
print i.get_attribute("name")
最好使用显式等待:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 5)
input_element = wait.until(EC.presence_of_element_located((By.NAME, 'quantity')))
更多关于等待的信息答案几乎在标题中;)