Home > other >  Issues with opening browser window in full screen using Selenium WebDriver Chrome
Issues with opening browser window in full screen using Selenium WebDriver Chrome

Time:10-03

I am currently doing a project where a RFID tag is tapped, and the associated webpage opens on Chrome (using Selenium). I used Selenium because I wanted to ensure that each webpage that was opened would just open on the same tab, so I wouldn't have multiple tabs open at any one time. I am now wanting when the code is run, for all webpages to be opened in full screen mode (without the search bar).

My code is as follows - I am using "driver.fullscreen_window()" as the code to open it fullscreen . Currently the tester Facebook webpage, will start with a maximised full screen, and will immediately turn back into a half screen with the search bar. Therefore, I was wondering if anyone had any ideas. I am a beginner, so any help would be fabulous.

    import RPi.GPIO as GPIO
    from mfrc522 import SimpleMFRC522
    import subprocess
    from selenium import webdriver
    from time import sleep
    driver = webdriver.Chrome()
    
    driver.fullscreen_window()
    
    link1="http://facebook.com.au"
    link2="http://netflix.com.au/"
    link3="http://google.com.au"
    
    
    reader = SimpleMFRC522()
    last_id=None
    
    driver.get(link1)
    
    while True:
        print("Place tag")
        print (id)
        
        id,text=reader.read()
        if last_id == id:
            pass
        
        else:
            if id == 397491194568:
                driver.get(link2)
    
            elif id == 769847466731:
                driver.get(link3)
    
        
        last_id = id

CodePudding user response:

Instead of driver.fullscreen_window() try passing start-maximized argument to driver options, as following:

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

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)

CodePudding user response:

After launching the URL, make the window as fullscreen_window()

driver.get(link1)

driver.fullscreen_window()
  • Related