Selenium Webdriver自动重定向

时间:2017-04-04 19:48:43

标签: javascript java selenium

问题描述:

我目前正在尝试用Java设置Selenium webdriver。 但是,每次我尝试加载此特定网页时,Expected Website我最终都会使用此Unintentional Website。无论我使用哪种驱动程序(Firefox,Chrome,Edge),我总会被重定向,我找不到任何解决方案来克服这个问题。请注意,页面在页面加载过程中加载了一些JS。这可能导致此重定向。

但是,如果我使用标准浏览器,我会按预期获得预期网站。

目标:

使用Selenium webdriver加载此网站:Expected Website

其他信息:

到目前为止我使用的代码:

     System.setProperty("webdriver.gecko.driver", "E:/Downloads/geckodriver.exe");
     File pathToBinary = new File(
     "C:/Program Files (x86)/Mozilla   Firefox/firefox.exe");

     FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
     FirefoxProfile firefoxProfile = new FirefoxProfile();
     driver = new FirefoxDriver(ffBinary,firefoxProfile);

     driver.get("https://www.liketoknow.it/featured");
        try {
             Thread.sleep(10000);
                }catch (InterruptedException e) {}

     driver.quit();

2 个答案:

答案 0 :(得分:0)

发生这种情况的原因如下:

如果要打开此页面,则必须授予访问权限。要这样,您必须首先登录主网页。

对于其他有类似问题被重定向的人:

在设置Webdriver并切换到移动设备或PC / MAC时使用其他用户代理,具体取决于您的需求。

干杯

答案 1 :(得分:-2)

您是否看到/ features正在重定向到根网站?

我会先做到这一点。可能是与之相关的事情,如果您首先连接到https://www.liketoknow.it/,结果会相同。