如何使用Python单击selenium在“https://maps.mapmyindia.com/direction”上的“get routes”?谢谢你的帮助!你知道吗
我试过什么? 我遵循了这个“python selenium click on button”,但它没有点击。你知道吗
from selenium import webdriver
#from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
#from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox(executable_path=r'C:\Users\User\Desktop\pyCode\geckodriver-v0.21.0-win64\geckodriver.exe')
driver.get("https://maps.mapmyindia.com/direction")
startLocation = driver.find_element_by_id("auto_start")
startLocation.send_keys("28.4592,77.0727")
endLocation = driver.find_element_by_id("auto_end")
endLocation.send_keys("28.4590,77.0725")
driver.find_element_by_css_selector('div.col-xs-6.pull-right.text-right').click()
要在
https://maps.mapmyindia.com/direction
上单击文本为GET ROUTES的元素,您需要:style="display: none;"
click()
方法。你知道吗代码块:
浏览器快照:
我查看了页面,似乎“获取路由”按钮有一个与之关联的id。你可以用这个
所以代码的最后一行应该是:
也可以使用其他选择器:
编写测试脚本时,在将选择器包括在测试脚本中之前,始终可以验证浏览器中的选择器。下面是验证选择器的几种简单方法:
document.getElementById("get_d")
。如果您使用的id有效,则应该在浏览器控制台中返回一个元素。你知道吗$x("//a[text()='Get routes']")
行。这还将返回与您提到的xpath相关联的所有元素$$("#get_d")
。与xpath方法类似,这将返回与您提到的css选择器相关联的所有元素相关问题 更多 >
编程相关推荐