I've been using selenium webdriver; however, I am now attempting to interact with a page using Java (this is new to me). In attempting to do this, I've found this video that appears to be exactly what Im looking for:
https://www.youtube.com/watch?v=bBRFVIEiFIE
I keep getting an error message generated from the second line of the code:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
This is the error message:
Traceback (most recent call last):
File "C:\Users\erich\Desktop\SeleniumDrivers\State Scrape Java.py", line 2, in <module>
from webdriver_manager.chrome import ChromeDriverManager
File "C:\Python27\lib\site-packages\webdriver_manager\chrome.py", line 4, in <module>
from webdriver_manager.driver import ChromeDriver
File "C:\Python27\lib\site-packages\webdriver_manager\driver.py", line 77
self.auth_header = {'Authorization': f'token {self._os_token}'}
^
SyntaxError: invalid syntax
I have made sure to pip install webdriver-manager and have attempted the two possible options on pypi.
Any help will be greatly appreciated!
CodePudding user response:
Try:
#selenium4 with python [pip install selenium4)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
#options to add as arguments
from selenium.webdriver.chrome.options import Options
option = webdriver.ChromeOptions()
option.add_argument("start-maximized")
#chrome to stay open
option.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get('https://www.example.com/')