【问题标题】:How to input Values in Google Maps using Python/Selenium如何使用 Python/Selenium 在 Google 地图中输入值
【发布时间】:2019-07-25 18:37:41
【问题描述】:

我无法正确使用发送键来输入值。

我希望能够在文本框中插入文本。

尝试了两种不同的方法

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
driver = webdriver.Chrome('/Users/.../Documents/chromedriver')

driver.get('http://codepad.org/')
text_area = driver.find_element_by_id('textarea')
text_area.send_keys("This text is send using Python code.")


from selenium import webdriver

driver = webdriver.Chrome('/Users/.../Documents/chromedriver')
driver.get( 'https://www.google.com/maps/dir///@36.0667234,-115.1059052,15z')
driver.find_element_by_xpath("//*[@placeholder='Choose starting point, or click on the map...']").click()
driver.find_element_by_xpath("//*[@placeholder='Choose starting point, or click on the map...']").clear()
driver.find_element_by_xpath("//*[@placeholder='Choose starting point, or click on the map...']").send_keys("New York")

在我试图将值放入的字段中输入一个值

【问题讨论】:

  • 你遇到了什么错误?两个代码对我来说都很好。

标签: python-3.x selenium web-scraping beautifulsoup


【解决方案1】:

这是您可以使用的代码,它将等待元素呈现,然后在输入框中设置值。

WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH, "(//input[@class='tactile-searchbox-input'])[1]"))).send_keys("new york")

顺便说一句,您需要以下导入才能使用上述代码中使用的显式等待。

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

【讨论】:

    猜你喜欢
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    相关资源
    最近更新 更多