Selenium webdriver.Firefox() is not callable - selenium

I hope this is something simple, it feels like it. But it is beyond me at the moment.
I am a new starter with Selenium, I want to automatically extract information from a website and this seems a good method.
For a change I have started doing this on Windows 10 and I want program in Python so I am using PyCharm. I have installed Selenium using pip install selenium and if I use the python command line shell with the following:
from selenium import webdriver
driver = webdriver.Firefox()
I get the following error message:
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> driver = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Damo\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 81, in __init__
self.binary, timeout)
File "C:\Users\Damo\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 51, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Users\Damo\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Users\Damo\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 98, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
When I type the same within PyCharm the IDE tells me that this term webdriver.Fiefox results in Firefox is not callable
Have I failed to install something?
>

Not meant as a silly reaction, but do you have the latest version of Firefox installed on your machine?

Related

Python Selenuim Crashes

When I run my code it crashes please help and this was made late at night so I may have missed something obv. Instead of launching chrome driver like my other programs Ive made it runs actual chrome. is there a fix?
from selenium.webdriver.common.proxy import Proxy, ProxyType
import time
# change 'ip:port' with your proxy's ip and port
proxy_ip_port = '95.217.168.246:8888'
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = proxy_ip_port
proxy.ssl_proxy = proxy_ip_port
capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)
# replace 'your_absolute_path' with your chrome binary absolute path
driver = webdriver.Chrome(r'C:\Users\andre\Desktop\Python dsicord bot\chromedriver',
desired_capabilities=capabilities)
driver.get('http://whatismyipaddress.com')
time.sleep(8)```
**Error:**
```DevTools listening on ws://127.0.0.1:57598/devtools/browser/120e371a-b935-4d04-9057-de3f728ce8b0
Traceback (most recent call last):
File "c:\Users\andre\Desktop\Python dsicord bot\sys.py", line 17, in <module>
driver = webdriver.Chrome(r'C:\Users\andre\Desktop\Python dsicord bot\chromedriver',
File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\andre\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\andre\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\andre\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\andre\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.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 93
Current browser version is 92.0.4515.159 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe```
This error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created:This version of ChromeDriver only supports Chrome version 93
is basically you do not have compatible version of browser and browser driver.
as of 29th-Aug-2021
Latest stable release: ChromeDriver 92.0.4515.107
and Google chrome browser version is Version 92.0.4515.159 (Official Build) (64-bit)
Download link for chromedriver, try to get 92.0, and that should help you past this issue.

driver.get(URL) not navigating to the specified URL

The webdriver is opening the browser but not navigating to the specified URL, and is returning the following exception:
Traceback (most recent call last):
File "C:/Users/91800/PycharmProjects/Automation/automation.py", line 3, in <module>
driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\Google\Chrome\\Application\\chrome.exe')
File "C:\Users\91800\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\91800\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\91800\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\Google\Chrome\\Application\\chrome.exe')
driver.get('https://www.google.com/')
so first check whether your chrome version is the same as your web driver version..otherwise, there might be an issue executing the code
#to check the chrome version:
go to help in google chrome then to about google chrome and you will find a version there
#install the specific version of web driver from URL("https://chromedriver.chromium.org/downloads")
and...
it should be fine !!!

why does selenium code execute successsfully only in debug mode but fail in run mode?

C:\apache-tomcat-8.0.27>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (
Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> webdriver.__version__
'3.0.2'
>>>
the selenium python testing code as the following:
driver.get("http://localhost:8080/")
self.assertEqual("Cubiender", driver.title)
driver.find_element_by_id("login_email").clear()
driver.find_element_by_id("login_email").send_keys("gin#cubi.com")
driver.find_element_by_id("login_pwd").clear()
driver.find_element_by_id("login_pwd").send_keys("pass")
driver.find_element_by_css_selector("input[type=\"submit\"]").click()
driver.find_element_by_link_text('Project List')
sleep(0.05)
driver.find_element_by_xpath("//input[#value='2588']").click()
sleep(0.05)
driver.find_element_by_css_selector("div.menu > #inquireProject").click()
the above code can run successfully in debug mode ,but will be failed when running at
driver.find_element_by_xpath("//input[#value='2588']").click()
even i added sleep
stacktrace:
C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.3.2\helpers\pycharm\utrunner.py" F:\python\sub_proj2.py true
Testing started at 10:53 ...
Error
Traceback (most recent call last):
File "F:\python\sub_proj2.py", line 41, in test_untitled
driver.find_element_by_css_selector("span.triangle").click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 437, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: span.triangle
Process finished with exit code 0
Please share the stacktrace.
To me it seems,
Either your value='2588 is a dynamic one and changing with every instance load.
May be the sleep halts the whole process. Why don't you use wait, an example mentioned below.
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID,'someid')))
It is probably because in debug mode, it has more time to find the element. Try to increase sleep time or other solution to make sure the element is loaded.

Selenium chrome driver No Such Session

OS: OSX 10.12.2
Selenium Version: 2.52.0 Scrapy
Browser: Chrome
Browser Version: 55.0.2883.95 (64-bit)
Hi,
I'm trying to use selenium on my project. But I'm getting No such session error. when I use it with latest chrome driver. Also You can find error below.
Traceback (most recent call last):
File "/Users/user/Library/Python/2.7/lib/python/site-packages/twisted/internet/defer.py", line 651, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/Users/user/Downloads/Test-2/ecommerce_bot/ecommerce_bot/spiders/hepsiburada.py", line 67, in parseProductComments
self.browser.get(response.url)
File "/Users/user/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 248, in get
self.execute(Command.GET, {'url': url})
File "/Users/user/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/Users/user/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: no such session
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.12.2 x86_64)
Also This my code.
self.browser.get("url")
xpath = self.browser.find_element_by_xpath("/html/head/script[17]")
And Browser
def __init__(self):
super(HepsiburadaSpider, self).__init__()
chromedriver = "/Users/user/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
self.browser = webdriver.Chrome(chromedriver)
This was happening to me. I found that downgrading my local version of Chrome to 53.0.2785.116 enabled testing to happen with Protractor (again). This is independent of the version specified in standalone.
Not a great solution (as this is your local version and it will wipe your browser history), but until the bug detailed below is addressed, the one that will allow local testing with Protractor and Chrome.
http://www.slimjet.com/chrome/google-chrome-old-version.php
Apparently there is a know bug with web driver-manager that does not allow it to be updated to 2.24
https://github.com/angular/webdriver-manager/issues/93
Protractor itself has a config file so make sure the version you are using has chromedriver using version 2.23 at the very highest. I am using protractor 3.1.0 giving me
"webdriverVersions": {
"selenium": "2.53.1",
"chromedriver": "2.23",
"iedriver": "2.51.0"
}
Because of this bug your local Chrome version will be too far ahead of what the webdriver-manager can support or is expecting (in this case creating a session).
If the browser is brought to an older version of Chrome it will be necessary to prevent Google updates as Chrome will attempt to move to the most current version every time the browser is reopened.

How do I run headless selenium on Ubuntu Server

I'm trying to run headless selenium and to get to grips with it I've set up a new droplet on Digital Ocean (Ubuntu 16).
I am following this tutorial but I'm getting the following error when I run the script.
Traceback (most recent call last):
File "pyvirtualdisplaytest.py", line 12, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f981d0dc190>> ignored
What should I do? Thanks for your help.
Download the gecko driver from https://github.com/mozilla/geckodriver/releases/tag/v0.11.1
export PATH=$PATH:/loaction of the downloaded geckodriver
Run your Code.
If you get the following Exception
selenium.common.exceptions.WebDriverException: Message: Expected
browser binary location, but unable to find binary in default
location, no 'moz:firefoxOptions.binary' capability provided, and no
bina ry flag set on the command line
Kindly, check the geckodriver and firefox should be of either 32 or 64 bit
Otherwise. Provide the FirefoxBinary path in the code to the FirefoxDriver() using FireFoxBinary Object.