当我尝试使用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!!!");
}
}
}
答案 0 :(得分:0)
我认为您的代码没有任何重大问题。你能试试修改过的代码块吗?
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!!!");
}
}
}