Home > Mobile >  Minimize Selenium
Minimize Selenium

Time:10-21

I want Selenium to work in the background.

DRIVER=webdriver.Chrome('/Applications/chromedriver')
driver.minimize_window()

But then I can't use following code:

ActionChains(DRIVER).move_by_offset(10,10).click().perform() # Clicks on a specific area, I can't work with xpath here.

Can someone help me?

CodePudding user response:

If you want to run selenium in background, Please use headless mode.

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--disable-infobars")
options.add_argument("--start-maximized")
options.add_argument('--window-size=1920,1080')
DRIVER= webdriver.Chrome(/Applications/chromedriver, options=options)

then you can write this line of code

ActionChains(DRIVER).move_by_offset(10,10).click().perform()

with bit modification :

ActionChains(DRIVER).move_by_offset(10,10).pause(2).click().perform()

CodePudding user response:

If don't want the Chrome web browser window to appear when performing a web scrape easiest option is run it in headless mode. You can still click buttons, and submit form actions, etc.

options = webdriver.ChromeOptions()
options.add_argument('headless')
pathToChromeDriver = '/Applications/chromedriver'
driver = webdriver.Chrome(executable_path=pathToChromeDriver,
                          options=options)
  • Related