Arguments not being applied to Google chromedriver in Selenium with python

和自甴很熟 提交于 2020-01-03 04:36:21

问题


I'm using selenium with python and chromedriver (webdriver) on OS X (Yosemite)

I'm trying to add arguments to my driver instance like so:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--start-maximized')
webdriver.Chrome(executable_path='/Library/Python/2.7/site-packages/selenium/webdriver/chrome/chromedriver', chrome_options=chrome_options)

The browser window creates fine but it doesn't maximise.

Even ignoring that particular argument, no matter which arguments I supply they never seem to be applied. Am I missing something?

Edit: Seems I can pass the mobile emulation options without any problems. So the issue might be contained to passing argument type options.


回答1:


You are doing it correctly, --start-maximized just doesn't work on mac.

To maximize the chrome window - use maximize_window():

maximize_window()

Maximizes the current window that webdriver is using

driver.maximize_window()


来源:https://stackoverflow.com/questions/27309508/arguments-not-being-applied-to-google-chromedriver-in-selenium-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!