i'm trying out Python Selenium with my main browser, Opera, but i get a massive error when i execute the script, here's the python script:
from selenium import webdriver
path = r"C:\Users\sleep\Programs\operadriver_win64\operadriver.exe"
driver = webdriver.Opera(executable_path=path)
driver.get('https://youtube.com')
And here's the error:
Traceback (most recent call last):
File "C:\Users\sleep\Programs\Status-Entrega\main.py", line 6, in <module>
driver = webdriver.Opera(executable_path=r'C:\Users\sleep\Programs\operadriver_win64\operadriver.exe')
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 79, in __init__
OperaDriver.__init__(self, executable_path=executable_path,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 55, in __init__
ChromiumDriver.__init__(self,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\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: cannot find Opera binary
(Driver info: operadriver=91.0.4472.77 (1cecd5c8a856bc2a5adda436e7b84d8d21b339b6-refs/branch-heads/4472#{#1246}),platform=Windows NT 10.0.19042 x86_64)
How can i fix this?
can you try this :
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
options.binary_location = r'C:\opera.exe path'
driver = webdriver.Opera(opera_options = options,
executable_path=r'C:\operadriver.exe path')
it might work, don't forget one is the opera path and one is the operadriver path
This link may help: https://github.com/operasoftware/operachromiumdriver/blob/master/examples/desktop.py
import time
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('path/to/operadriver')
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
driver.get('https://www.google.com/')
input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')
time.sleep(5) #see the result
driver.quit()
Related
I am trying the code from the following URL and it seems to be working for Opera-
Drive Opera with selenium python
import time
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('.\operadriver.exe')
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
driver.get('https://www.google.com/')
input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')
time.sleep(5) #see the result
driver.quit()
But I get error when trying to search in Youtube with the following Xpath code-
driver.get('https://youtube.com/')
input_txt = driver.find_element_by_xpath('//*[#id="search"]')
input_txt.send_keys('operadriver\n')
Error
Traceback (most recent call last):
File "C:\Users\admin\Desktop\py\-test\web\selnm\ytb1.py", line 39, in <module>
input_txt.send_keys('operadriver\n')
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=93.0.4577.82)
(Driver info: operadriver=93.0.4577.63 (ff5c0da2ec0adeaed5550e6c7e98417dac77d98a-refs/branch-heads/4577#{#1135}),platform=Windows NT 6.1.7601 SP1 x86_64)
Any suggestion why it's not working for youtube?
Try this
driver.get('https://youtube.com/')
input_txt = driver.find_element_by_xpath('//input[#id="search"]')
input_txt.click()
time.sleep(1)
input_txt.send_keys('operadriver\n')
I am trying to open a chrome window that remembers my browser history, cookies, etc. I was able to do this by adding the Chrome Options, BUT when I add these options my driver.get() statement no longer works. The script just opens a chrome window but won't go to the specified website. If I remove the options it takes me to the website, but then I don't have the browser history data I want.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PATH = '/Users/myname/Projects/chromedriver'
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=/Users/myname/Library/Application Support/Google/Chrome/')
driver = webdriver.Chrome(executable_path=PATH, chrome_options=options)
driver.get('https://www.basketball-reference.com/')
I also receive this error:
Traceback (most recent call last):
File "app_store.py", line 9, in <module>
driver = webdriver.Chrome(executable_path=PATH, options=options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
I think you've got a syntax error here
driver = webdriver.Chrome(executable_path=PATH, chrome_options=options)
The argument is just options, so it should be
driver = webdriver.Chrome(executable_path=PATH, options=options)
Try making two different drivers, one for Chrome Options and one for the website.
I am working on a web application, and was attempting to run a basic test script with seleium, just to make sure my code was working
from selenium import webdriver
import time
import os
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = os.getcwd()
driver = webdriver.Chrome(chrome_options=options, executable_path=r'./chromedriver')
driver.get('http://codepad.org')
I have the chromedriver in the current directory, and I think I am using the correct version of the chromedriver (75.0.3770.90). The full error I am getting is:
Traceback (most recent call last):
File "test.py", line 9, in <module>
driver = webdriver.Chrome(options=options, executable_path=r'./chromedriver')
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/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: Failed to create a Chrome process.
If anyone has any insight into a fix I could try that would be greatly appreciated!
Remove/comment the below line.
options.binary_location = os.getcwd()
As the binary is not located in the current working directory you are getting this error message.
binary_location is the location where your chrome.exe is located.
And make sure you have the chromedriver in the same folder you have this test located. Otherwise your script will fail with below error message.
selenium.common.exceptions.WebDriverException: Message: 'chromedriver` executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
The value binary_location must be an .exe file which specify the chrome.exe you want to run.
So this code works for me:
chrome_options = Options()
chrome_options.binary_location = '****\\chrome.exe'
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver\\chromedriver.exe"), options=chrome_options)
Hope it helps you
I am trying the following script and can't get it to open Webdriver:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome('/usr/bin/google-chrome')
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
This produces the following error message:
Traceback (most recent call last):
File "scraper.py", line 4, in <module>
driver = webdriver.Chrome('/usr/bin/google-chrome')
File "/home/joseph/.local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/home/joseph/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/joseph/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: 1
I'm using Ubuntu 16.04 running on Windows 10. Any ideas what this could be?
EDIT:
Now I'm doing this with chromedriver, which I unzipped to the same directory as the script.
driver = webdriver.Chrome(executable_path='./chromedriver')
I get the following error instead of the previous one:
Traceback (most recent call last):
File "scraper.py", line 4, in <module>
driver = webdriver.Chrome(executable_path='./chromedriver')
File "/home/joseph/.local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/home/joseph/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/home/joseph/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/joseph/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/home/joseph/.local/lib/python2.7/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: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752),platform=Linux 4.4.0-43-Microsoft x86_64)
While working with Selenium v3.11.0, ChromeDriver v2.36 and Chrome v64.x you have to download the latest ChromeDriver from the ChromeDriver - WebDriver for Chrome and place it within your system. Next while initializing the WebDriver and the WebBrowser you have to mention the absolute path of the ChromeDriver as follows :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()
Note : At the end of your Test Execution instead of close() invoke the quit() method so the WebDriver and WebBrowser both are destroyed.
You may need to try various versions of the driver depending on version of chrome. Also, make sure your path is correct and pointing to executable driver file(.exe)
driver = webdriver.Chrome(executable_path='./chromedriver/chromedriver.exe')
Here's my code and the error Python provides.
I'm a beginner using Python 3.6. Can anyone helps find out what's wrong? Many thanks.
#!/usr/bin/env python
#coding: utf-8
from selenium import webdriver
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
browser = webdriver.Chrome()
browser.get('http://www.bing.com/')
Traceback:
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\cxy61.com - html\python spider\001 selenium import.py", line 8, in <module>
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception: Chrome version must be >= 58.0.3029.0
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.14393 x86_64)
You have to take care of a couple of things as follows:
As you are using chromedriver v2.31 the error clearly states Chrome version must be >= 58.0.3029.0. So you need to bump up your Google Chrome version to v58.0 or above.
If you want to specify the absolute path of the chromedriver within single quotes '...' then you have to provide single forward slashes \ only.
If you are assigning the webdriver instance to the driver, you have to use the driver instance only to open any url
Here is your own code with the above mentioned changes:
from selenium import webdriver
driver = webdriver.Chrome(r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('http://www.bing.com/')