如何从 selenium python 的下拉列表中输入值?
How to Input value from dropdown in selenium python?
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
EMAILFIELD = (By.ID, "username")
PASSWORDFIELD = (By.ID, "password")
LOGINBUTTON = (By.ID, "Login")
CLICKBUTTON= (By.ID, "thePage:rtForm:createButton")
QUICKFINDSEARCH = (By.ID, "quickFindInput")
browser = webdriver.Chrome(
executable_path=r"C:/Users/RYadav/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python 3.8/chromedriver.exe")
browser.get('https://fleet.my.salesforce.com/')
# wait for email field and enter email
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(EMAILFIELD)).send_keys("ryadav@gmail.com")
# wait for password field and enter password
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(PASSWORDFIELD)).send_keys("1234zxcvb")
# Click Login - same id?
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(LOGINBUTTON)).click()
#direct new reportfield
browser.get('https://fleet.my.salesforce.com/reportbuilder/reportType.apexp')
#search the Users from dropdown and click button
select = Select(webdriver.find_element_by_id("quickFindInput"))
select.select_by_visible_text("Users")
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(CLICKBUTTON)).click()
Please suggest how to input a value from dropdown to the above code. This code throws Attribute Error.
Traceback (most recent call last):
File "C:/Users/RYadav/PycharmProjects/ElementProject/SalesforceUrl.py", line 30, in <module>
select = Select(webdriver.find_element_by_id("quickFindInput"))
AttributeError: module 'selenium.webdriver' has no attribute 'find_element_by_id'
你们太亲密了。在整个程序中,您一直在使用 browser
作为 实例。但是在行中通过不同的名称 webdriver
调用:
select = Select(webdriver.find_element_by_id("quickFindInput"))
您需要将行更改为:
select = Select(browser.find_element_by_id("quickFindInput"))
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
EMAILFIELD = (By.ID, "username")
PASSWORDFIELD = (By.ID, "password")
LOGINBUTTON = (By.ID, "Login")
CLICKBUTTON= (By.ID, "thePage:rtForm:createButton")
QUICKFINDSEARCH = (By.ID, "quickFindInput")
browser = webdriver.Chrome(
executable_path=r"C:/Users/RYadav/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python 3.8/chromedriver.exe")
browser.get('https://fleet.my.salesforce.com/')
# wait for email field and enter email
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(EMAILFIELD)).send_keys("ryadav@gmail.com")
# wait for password field and enter password
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(PASSWORDFIELD)).send_keys("1234zxcvb")
# Click Login - same id?
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(LOGINBUTTON)).click()
#direct new reportfield
browser.get('https://fleet.my.salesforce.com/reportbuilder/reportType.apexp')
#search the Users from dropdown and click button
select = Select(webdriver.find_element_by_id("quickFindInput"))
select.select_by_visible_text("Users")
WebDriverWait(browser, 5).until(EC.element_to_be_clickable(CLICKBUTTON)).click()
Please suggest how to input a value from dropdown to the above code. This code throws Attribute Error.
Traceback (most recent call last):
File "C:/Users/RYadav/PycharmProjects/ElementProject/SalesforceUrl.py", line 30, in <module>
select = Select(webdriver.find_element_by_id("quickFindInput"))
AttributeError: module 'selenium.webdriver' has no attribute 'find_element_by_id'
你们太亲密了。在整个程序中,您一直在使用 browser
作为 webdriver
调用:
select = Select(webdriver.find_element_by_id("quickFindInput"))
您需要将行更改为:
select = Select(browser.find_element_by_id("quickFindInput"))