0

我想通过从我的代码中发送预定义的值来自动化这个网站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 时,文本框(送货地址)都会自行刷新。我已经尝试了很多东西,但无法提出解决方案。

4

1 回答 1

1

问题是您无法在定位器内的元素中设置文本。尝试这个:

# Get the element object
user_box = driver.find_element_by_id("txtPickUp")
# Send text to the element.
user_box.send_keys("XYZ")
于 2018-03-29T14:10:24.670 回答