【问题标题】:I'm not able to launch mod header extension with selenium我无法使用 selenium 启动 mod 标头扩展
【发布时间】:2017-11-18 07:17:46
【问题描述】:

当我尝试使用 selenium 启动 mod 标头扩展时,我收到错误消息:“对服务器的请求已被扩展阻止。 尝试禁用您的扩展程序。 ERR_BLOCKED_BY_CLIENT"

我正在使用 selenium 3.0.4

硒中的代码:

package mrLogin;
import java.io.File;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.JavascriptExecutor;

 public class Login {
    public static String driverPath = 
"C:/auto/Mass_Retail_Auto/bin/mrLogin/";
    public static WebDriver driver ;
    public static JavascriptExecutor js=(JavascriptExecutor) driver;
    public static void main(String[] args) {
        try{        
        System.out.println("launching chrome browser");
        System.setProperty("webdriver.chrome.driver", 
driverPath+"chromedriver.exe");
        driver = new ChromeDriver();
        ChromeOptions options = new ChromeOptions();
        options.addExtensions(new File []{(new 
File("C:/auto/Mass_Retail_Auto/bin/mrLogin/modheader 2.1.2.crx"))});
        driver.navigate().to("chrome-
extension://idgpnmonknjnojddfkpgkljpfnnfcklj/icon.png");
        js.executeScript(
                "localStorage.setItem('profiles', JSON.stringify([{                
" +
                "  title: 'Selenium', hideComment: true, appendMode: '',           
" +
                "  headers: [                                                      
" +
                "    {enabled: true, name: 'token1', value: '01234', 
comment: ''}, " +
                "    {enabled: true, name: 'token2', value: '56789', 
comment: ''}  " +
                "  ],                                                              
  " +
                "  respHeaders: [],                                                
   " +
                    "  filters: []                                                     
    " +
                "}]));                                                             
", args );

        driver.navigate().to("http://google.com");
        }
        catch(Exception e ){ 
            e.printStackTrace();

        }
        finally {
        //driver.close();
        System.out.println("Browser closed!!!");
        }
    }

 }

【问题讨论】:

    标签: java selenium google-chrome-extension webdriver mod-headers


    【解决方案1】:

    我认为您的代码没有任何重大问题。可以试试修改后的代码块吗:

    package mrLogin;
    import java.io.File;
    import java.util.List;
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.JavascriptExecutor;
    
     public class Login {
        public static String driverPath = "C:/auto/Mass_Retail_Auto/bin/mrLogin/";
        public static WebDriver driver ;
        public static void main(String[] args) {
        try{        
            System.out.println("launching chrome browser");
            System.setProperty("webdriver.chrome.driver", driverPath+"chromedriver.exe");
            driver = new ChromeDriver();
            ChromeOptions options = new ChromeOptions();
            options.addExtensions(new File []{(new File("C:/auto/Mass_Retail_Auto/bin/mrLogin/modheader 2.1.2.crx"))});
            driver.navigate().to("chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/icon.png");
            JavascriptExecutor js=(JavascriptExecutor) driver;
            js.executeScript("localStorage.setItem('profiles', JSON.stringify([{  
            " +
                    "  title: 'Selenium', hideComment: true, appendMode: '',           
            " +
                    "  headers: [                                                      
            " +
                    "    {enabled: true, name: 'token1', value: '01234', 
            comment: ''}, " +
                    "    {enabled: true, name: 'token2', value: '56789', 
            comment: ''}  " +
                    "  ],                                                              
              " +
                    "  respHeaders: [],                                                
               " +
                        "  filters: []                                                     
                " +
                    "}]));                                                             
            ", args );
    
            driver.navigate().to("http://google.com");
            }
        catch(Exception e ){ 
                    e.printStackTrace();
            }
        finally {
            driver.close();
            System.out.println("Browser closed!!!");
            }
        }
    
     }
    

    【讨论】:

    • 还是同样的问题
    猜你喜欢
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多