简体   繁体   English

如何使用 Selenium Java 通过 ChromeOptions 和 addArguments 打开最大化和抑制信息栏的 Chrome 浏览器

[英]How to open Chrome browser maximized and supressing the infobars through ChromeOptions and addArguments using Selenium Java

I am using Chrome driver on mac, and when opening the browser I have these options我在 Mac 上使用 Chrome 驱动程序,打开浏览器时我有这些选项

WebDriver driver; 
@Before public void setup() { 
    ChromeOptions options = new ChromeOptions(); 
    options.addArguments("use-fake-ui-for-media-stream"); 
    options.addArguments("--disable-web-security"); 
    options.addArguments("--start-maximized"); 
    options.addArguments("disable-infobars"); 
    System.setProperty("webdriver.chrome.driver","/Users/animanukyan/Drivers/chromedriver"); 
    driver = new ChromeDriver(options); 
} 

but non of them seems to work, browser opens not maximized, infobars are there...但它们似乎都不起作用,浏览器打开没有最大化,信息栏在那里......

Using ChromeDriver to open Chrome maximized and without infobars :使用ChromeDriver打开Chrome最大化且没有信息

Previously we handled through the argument disable-infobars and you can find a couple of relevant discussions in:以前我们通过参数disable-infobars ,您可以在以下位置找到一些相关讨论:

But from Chrome v76.x onwards to suppress the infobars you have to:但是从Chrome v76.x开始,要抑制信息栏,您必须:

  • Use an instance of ChromeOptions and addArguments to start-maximized .使用ChromeOptionsaddArguments的实例来start-maximized
  • Use ExperimentalOption to enable-automation .使用ExperimentalOption enable-automation
  • Use ExperimentalOption to set useAutomationExtension as false .使用ExperimentalOptionuseAutomationExtension设置为false
  • You can find a detailed discussion in Unable to hide “Chrome is being controlled by automated software” infobar within Chrome v76您可以在无法隐藏 Chrome v76 中的“Chrome 正在由自动化软件控制”信息栏中找到详细讨论

  • Code Block:代码块:

     import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class A_Chrome { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation")); options.setExperimentalOption("useAutomationExtension", false); WebDriver driver = new ChromeDriver(options); driver.get("https://www.google.co.in"); System.out.println(driver.getTitle()); driver.quit(); } }
  • Console Output:控制台输出:

     Google
  • Browser Snapshot:浏览器快照:

Chrome选项

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java将数据设置到Selenium Chrome驱动程序的ChromeOptions中? - How to set data into ChromeOptions to the Selenium Chrome driver using Java? 如何通过Selenium WebDriver使用ChromeOptions禁用通知 - How to disable notifications using ChromeOptions through Selenium WebDriver 在 Selenium 中使用 DesiredCapabilities 和 ChromeOptions 4 - Using DesiredCapabilities and ChromeOptions in Selenium 4 如何使用 Selenium 在 Chrome 浏览器上打开新标签页 - How to open new tab on Chrome browser using Selenium 线程“main”中的异常 java.lang.AbstractMethodError:接收器类 org.openqa.selenium.chrome.ChromeOptions 未使用 Selenium 定义错误 - Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeOptions does not define error using Selenium 如何使用Selenium和Java将控件从1个Chrome浏览器切换到另一个 - how to switch the control from 1 chrome browser to another using selenium with java 如何使用Java记录Selenium中启动的Chrome浏览器会话 - How to record chrome browser session launched in selenium using java 如何使用 Selenium Java 在 Chrome 浏览器中摆脱 cookie 通知 - How to get rid of cookies notification in chrome browser using Selenium Java 如何使用 java + selenium 设置 chrome 浏览器语言? - How to set chrome browser language using java + selenium? 如何使用Java代码在selenium中为Chrome浏览器设置代理 - How to set proxy for Chrome browser in selenium using Java code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM