【发布时间】:2021-12-11 23:46:36
【问题描述】:
我试图使用机器人 + seleniumLib 覆盖地理定位,所有文档都提到了这个 python 代码,使用 cdp 命令,但是在这种情况下我如何导入这个代码? 我读过一些关于使用关键字“创建 Webdriver”的内容,但真的不知道它是如何工作的。 谁能帮我解决这个问题?
.py 和 .robot 文件在同一个文件夹中。
.机器人文件
***Settings***
Library SeleniumLibrary
Library geo.py
Suite Teardown End
***Variables***
***Test Cases***
Test Location
Should appear the overrided location
***Keywords***
End
Close All Browsers
Should appear the overrided location
Open Browser https://browserleaks.com/geo Chrome
Wait Until Page Contains HTML5 Geolocation API
Scroll Element Into View xpath://*[@id="footer"]
Page Should Not Contain Element xpath://*[@alt="BR"] #flag img from my current country location
Sleep 5
Close Browser
.py 文件
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
def geoLocation_Test():
driver = webdriver.Chrome()
Map_coordinates = dict({
"latitude": 41.8781,
"longitude": -87.6298,
"accuracy": 100
})
driver.execute_cdp_cmd("Emulation.setGeolocationOverride", Map_coordinates)
【问题讨论】: