GVKun编程网logo

使用Selenium和Chrome设置代理服务器(selenium设置浏览器代理)

6

在本文中,我们将为您详细介绍使用Selenium和Chrome设置代理服务器的相关知识,并且为您解答关于selenium设置浏览器代理的疑问,此外,我们还会提供一些关于c#–在Selenium中为Ch

在本文中,我们将为您详细介绍使用Selenium和Chrome设置代理服务器的相关知识,并且为您解答关于selenium设置浏览器代理的疑问,此外,我们还会提供一些关于c# – 在Selenium中为Chrome驱动程序设置代理、ChromeOptions使用Selenium ChromeDriver for node.js导致参考错误、Chrome无法在使用Selenium用C#开发的Windows服务的服务器中打开、java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0的有用信息。

本文目录一览:

使用Selenium和Chrome设置代理服务器(selenium设置浏览器代理)

使用Selenium和Chrome设置代理服务器(selenium设置浏览器代理)

如何使用使用selenium和谷歌浏览器的代理服务器?我附加了代码,但不确定是否会更改实际的代理服务器。

# selenium importsfrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport randomPROXY ="88.157.149.250:8080";chrome_options = webdriver.ChromeOptions()chrome_options.add_argument(''--proxy-server=%s'' % PROXY)# //a[starts-with(@href, ''https://www.amazon.com/'')]/@hrefLINKS_XPATH = ''//*[contains(@id,"result")]/div/div[3]/div[1]/a''browser = webdriver.Chrome(executable_path="C:\\Users\Andrei\Downloads\chromedriver_win32\chromedriver.exe",                           chrome_options=chrome_options)browser.get(    ''https://www.amazon.com/s/ref=lp_11444071011_nr_p_8_1/132-3636705-4291947?rh=n%3A3375251%2Cn%3A%213375301%2Cn%3A10971181011%2Cn%3A11444071011%2Cp_8%3A2229059011'')links = browser.find_elements_by_xpath(LINKS_XPATH)for link in links:    href = link.get_attribute(''href'')    print(href)

答案1

小编典典
from selenium import webdriverPROXY = "88.157.149.250:8080" # IP:PORT or HOST:PORTchrome_options = webdriver.ChromeOptions()chrome_options.add_argument(''--proxy-server=%s'' % PROXY)chrome = webdriver.Chrome(chrome_options=chrome_options)chrome.get("http://google.com")

c# – 在Selenium中为Chrome驱动程序设置代理

c# – 在Selenium中为Chrome驱动程序设置代理

我在Chrome浏览器中使用C#for Automation的Selenium Webdriver.
我需要检查我的网页是否在某些区域(某些IP区域)中出现了问题.所以我必须在Chrome浏览器中设置代理.我尝试了下面的代码.代理正在设置但我收到错误.有人可以帮助我.
ChromeOptions options = new ChromeOptions();

        options.AddArguments("--proxy-server=XXX.XXX.XXX.XXX");

        IWebDriver Driver = new ChromeDriver(options);

        Driver.Navigate().GoToUrl("myUrlGoesHere");

当我运行此代码时,我在Chrome浏览器中收到以下消息:我尝试启用“代理”选项,但“禁用更改代理设置”选项.

*无法连接到代理服务器

代理服务器是充当计算机与其他服务器之间的中介的服务器.目前,您的系统已配置为使用代理,但Google Chrome无法连接到该代理.
如果您使用代理服务器…
检查您的代理设置或联系您的网络管理员以确保代理服务器正常工作.如果您认为自己不应该使用代理服务器:请转到Chrome菜单>设置>显示高级设置…>更改代理设置…> LAN设置并取消选择“为LAN使用代理服务器”.
错误代码:ERR_PROXY_CONNECTION_Failed *

解决方法

我正在使用Selenium 2.50.1的nuget包:
ChromeOptions options = new ChromeOptions();
proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy =
proxy.SslProxy = "127.0.0.1:3330";
options.Proxy = proxy;
options.AddArgument("ignore-certificate-errors");
var chromedriver = new ChromeDriver(options);

ChromeOptions使用Selenium ChromeDriver for node.js导致参考错误

ChromeOptions使用Selenium ChromeDriver for node.js导致参考错误

我正在尝试使用Selenium的ChromeDriver驱动程序来使用Chrome运行某些测试,但是使用时出现参考错误ChromeOptions

我的密码

我想强制使用某些选项,例如针对特定的用户配置文件对其进行测试。根据Selenium和ChromeDriver文档,这是我的文件test.js

opt = new chromeOptions(); // ERROR OCCURS HERE!opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");opt.addArguments("--user-data-dir=C:\\Users\\MyUserAccount\\AppData\\Local\\Google\\Chrome\\User Data");driver = new ChromeDriver(opt);// rest of my script goes here

错误

我正在使用命令执行此操作node test.js。这会在第一行上引发以下错误:

\path\to\test.js:1ction (exports, require, module, __filename, __dirname) { opt = new chromeOpti                                                                    ^ReferenceError: chromeOptions is not defined    at Object.<anonymous> (\path\to\test.js:1:73)    at Module._compile (module.js:456:26)    at Object.Module._extensions..js (module.js:474:10)    at Module.load (module.js:356:32)    at Function.Module._load (module.js:312:12)    at Function.Module.runMain (module.js:497:10)    at startup (node.js:119:16)    at node.js:902:3

值得一提的是,如果我跳过设置选项,并以此替换脚本的前四行,则可以使用,但是我无法设置需要设置的选项:

var webdriver = require(''selenium-webdriver'');var driver = new webdriver.Builder().    withCapabilities(webdriver.Capabilities.chrome()).    build();

我确定我确实缺少一些基本知识,但是我无法弄清楚这一点。如何使用Selenium和node.js为Chrome设置选项?

编辑后从我发现的一些文档的样本中删除了一些明显无效的语法。

答案1

小编典典

以下对我有用:

var webdriver = require("selenium-webdriver");var chrome = require("selenium-webdriver/chrome");// Make sure the PATH is set to find ChromeDriver. I''m on a Unix// system. You''ll need to adapt to whatever is needed for// Windows. Actually, since you say that you can get a browser to show// up if you don''t try to specify options, your ChromeDriver is// probably already on your PATH, so you can probably skip this.process.env["PATH"] += ":/home/user/src/selenium/";var options = new chrome.Options();// Commented out because they are obviously not what you want.// Uncomment and adapt as needed://// options.setChromeBinaryPath("/tmp/foo");// options.addArguments(["--blah"]);var driver = new webdriver.Builder().   withCapabilities(options.toCapabilities()).build();driver.get("http://www.google.com")

我已经使用各种值测试了上面的代码,并发现它可以工作。

如果要查看可以对该Options对象执行的其他操作,可以打开node_modules/selenium_webdriver/chrome.js并阅读源代码。这就是我找出上述方法的方式。

Chrome无法在使用Selenium用C#开发的Windows服务的服务器中打开

Chrome无法在使用Selenium用C#开发的Windows服务的服务器中打开

如何解决Chrome无法在使用Selenium用C#开发的Windows服务的服务器中打开?

下面是我的代码,它在调试模式下可以正常工作,并且在笔记本电脑上安装了服务,但可以正常工作,但是,如果我在服务器上安装了相同的服务,则不会打开chrome,也不会引发任何错误。

ChromeDriverService driverS = ChromeDriverService.CreateDefaultService();
            driverS.HideCommandPromptwindow = true;
            driverS.Port = 4444;
            ChromeOptions driverO = new ChromeOptions();
         
            // driverO.LeavebrowserRunning = true;
            driverO.Proxy = new Proxy { Kind = ProxyKind.Direct };
     

            string WPSPortalLink = "www.google.com";
            log.Info("opening chrome");
            driver = new ChromeDriver(driverS,driverO);

            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl(WPSPortalLink);
            log.Info("Link Opened");

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0

java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0

public class sikuli {

    public static void main(String[] args) throws Exception {
        //Screen screen=new Screen();
        //screen.click("//home//exeter//Pictures//googlechrome.png");
        System.setProperty("webdriver.chrome.driver","//home//exeter//Documents//chromedriver");
        WebDriver driver=new ChromeDriver();
        driver.get("https://mail.google.com");

Starting ChromeDriver 2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3) on port 11320
Only local connections are allowed.
Oct 19,2016 10:07:22 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session,assuming Postel’s Law holds true on the remote end
Oct 19,2016 10:08:22 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread “main” org.openqa.selenium.NoSuchSessionException: no such session
(Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.4.0-43-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
Build info: version: ‘unkNown’,revision: ‘350cf60’,time: ‘2016-10-13 10:43:56 -0700’
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unkNown error: Chrome Failed to start: exited abnormally

解决方法

看起来你在Linux机器上运行,所以“chromedriver”(没有.exe)应该没问题.只需确保您拥有最新的chrome和最新的Chrome驱动程序版本,并且您还拥有正确的“chromedriver”文件(64位上的文件).

我们今天的关于使用Selenium和Chrome设置代理服务器selenium设置浏览器代理的分享已经告一段落,感谢您的关注,如果您想了解更多关于c# – 在Selenium中为Chrome驱动程序设置代理、ChromeOptions使用Selenium ChromeDriver for node.js导致参考错误、Chrome无法在使用Selenium用C#开发的Windows服务的服务器中打开、java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0的相关信息,请在本站查询。

本文标签: