我希望通过从我的代码发送预先定义的值来自动化此网站https://www.avis.co.in。 但问题是我无法在传递地址文本框中发送文本。
from latlong import user
from lib import *
locality, city = user.split()
city = city.upper()
locality = locality.upper()
binary = FirefoxBinary('/usr/lib/firefox/firefox')
driver = webdriver.Firefox(firefox_binary=binary)
driver.get("https://www.avis.co.in")
driver.switch_to.window(driver.window_handles[-1])
driver.switch_to.window(driver.window_handles[0])
driver.find_element_by_xpath("//select[@id='DrpCity' and @name='DrpCity']/option[text()='Pune']").click()
user_box = driver.find_element_by_xpath("//select[@id='txtPickUp' and @name='txtPickUp']/[text()='XYZ']")
每当我发送XYZ时,文本框(传递地址)都会自行刷新。我尝试过很多东西,但无法提出解决方案。
答案 0 :(得分:1)
问题是您无法在定位器中的元素中设置文本。试试这个:
# Get the element object
user_box = driver.find_element_by_id("txtPickUp")
# Send text to the element.
user_box.send_keys("XYZ")