Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium按名称查找元素_Python_Selenium_Selenium Webdriver_Ui Automation_Webautomation - Fatal编程技术网

Python Selenium按名称查找元素

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

我正在使用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 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')))

更多关于等待的信息

答案几乎在标题中;)