I am learning selenium with chrome on mac.
I've managed to load the google home page with following code.
dir_path = os.path.dirname(os.path.realpath(__file__))
driver = webdriver.Chrome(dir_path+'/chromedriver')
driver.set_page_load_timeout('10')
driver.get('http://google.com')
time.sleep(4)
driver.quit()
based on that, I am trying to load a local html file with selenium.
dir_path = os.path.dirname(os.path.realpath(__file__))
driver = webdriver.Chrome(dir_path+'/chromedriver')
driver.set_page_load_timeout('10')
driver.get('/Users/selenium/test.html')
time.sleep(4)
driver.quit()
chrome launched with a weird string.
and got this error.
Traceback (most recent call last): File "/Users/pan/selenium.py", line 11, in driver.get(dir_path+'/game/dino.html') File "/Users/pan/anaconda3/envs/tf11/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get self.execute(Command.GET, {'url': url}) File "/Users/pan/anaconda3/envs/tf11/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/Users/pan/anaconda3/envs/tf11/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"} (Session info: chrome=73.0.3683.103) (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Mac OS X 10.13.6 x86_64)
what am i missing?
Try adding file://
as the protocol to your local file path. So, the code would then read:
driver.get('file:///Users/selenium/test.html')
As the exception says, The URL you are trying to get is invalid.
Selenium web driver accepts files.
Try the following:
driver.get('file://Users/selenium/test.html')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With