我希望该程序点击网站的输入。 我找到了带有类名的元素。
我试图更改班级名称,但不起作用。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
# Open Chrome
driver = webdriver.Chrome('C:/xampp/htdocs/pegasus/chromedriver')
# Going to website
driver.get("https://www.flypgs.com/en")
# Select button by class name and click on it.
frombtn = driver.find_element_by_class_name('select2-selection')
frombtn.click()
searchbtn = driver.find_element_by_class_name("select2-search__field")
searchbtn.click()
inputfrom = input('From: ')
searchbtn.send_keys(inputfrom)
tobtn = driver.find_element_by_xpath("//span[@class='select2-selection select2-selection--single']")
tobtn.click()
tosrcbtn = driver.find_element_by_xpath("//input[@class='select2-search__field']")
tosrcbtn.click()
toinput = input('To: ')
tobtn.send_keys(toinput)
time.sleep(1000000)
这是错误:
Exception has occurred: WebDriverException
Message: unknown error: Element <span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-labelledby="select2-8xub-container" aria-owns="select2-8xub-results" aria-activedescendant="select2-8xub-result-qvfa-AMS">...</span> is not clickable at point (144, 416). Other element would receive the click: <input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" role="textbox" maxlength="25">
(Session info: chrome=77.0.3865.120)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.17763 x86_64)
File "C:\xampp\htdocs\pegasus\app.py", line 25, in <module>
tobtn.click()