问题
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