首页 > 解决方案 > Selenium 地理定位测试

问题描述

在 selenium 上尝试此功能。我们是否需要与元素交互来设置所需的地理位置?到目前为止,这似乎对位置没有任何影响,因此需要进行一些澄清。

chrome_options = Options()
params = {
    "latitude": 50.1109,
    "longitude": 8.6821,
    "accuracy": 100
}


driver = webdriver.Chrome(executable_path='C:/chromedriver.exe', options=chrome_options)
driver.execute_cdp_cmd("Page.setGeolocationOverride", params)
driver.get("https://www.yellowpages.com/")
time.sleep(5)

例如,它适用于该站点,但在单击 geolocate 元素之后。那么,我们在网站上找到了这个元素吗?如果网站没有这样的地理定位元素怎么办?

driver.get("https://locations.dennys.com/search.html/")

time.sleep(10)

location_icon = driver.find_element_by_css_selector(".icon-geolocate")
time.sleep(10)
location_icon.click()

标签: pythonseleniumgeolocation

解决方案


推荐阅读