Python Selenium浏览器堆栈(& B)-连接到代理

ss2ws0br  于 2022-12-13  发布在  Python
关注(0)|答案(1)|浏览(146)

所以我尝试让我的浏览器堆栈任务使用代理,但我似乎不能让它工作。我正在运行一个浏览器堆栈本地服务器,通过语言绑定设置参数,它只是不工作。任何帮助将非常感谢,我不知道我做错了什么,因为我一直在遵循文档。
它应该连接到代理,但它不是。我也尝试添加一些选项到webdriver。远程功能没有运气。有没有错误,但从屏幕截图捕捉它是不使用代理,不知道为什么,因为我试图迫使它在。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from browserstack.local import Local

desired_cap = {
    'bstack:options' : {
        "os" : "Windows",
        "osVersion" : "10",
        "projectName" : "Take Screenshot Sample Test",
        "buildName" : "Take Screenshot Sample Build",
        "local" : "true",
        "seleniumVersion" : "4.0.0",
    },
    "browserstack.local" : "true",
    "browserstack.debug" : "true",
    "browserName" : "Chrome",
    "browserVersion" : "103.0",
    "forceLocal" : "true",
    "forceProxy" : "true",
}
local = Local()
local_args = { "key": "mykey" }
local_args["localproxyHost"] = "myproxyip"
local_args["localproxyPort"] = "8080"
local_args["localproxyUser"] = "user"
local_args["localproxyPass"] = "password"
local_args["forceProxy"] = "true"
local_args["forceLocal"] = "true"
local_args["state"] = "connected"
local_args["tunnelIdentifier"] = "tom"
local_args["localIdentifier"] = "tomjohn"
local.start(**local_args)
driver = webdriver.Remote(
    command_executor='https://myuser:mykey@hub-cloud.browserstack.com/wd/hub',
    desired_capabilities=desired_cap)
driver.get("https://www.whatismyipaddress.com")
driver.save_screenshot('screenshots.png')
driver.quit()
pjngdqdw

pjngdqdw1#

您似乎需要添加:

"localIdentifier": "tomjohn"

bstack:options中。可以尝试执行此操作吗?

相关问题