I am new to Selenium and am following the website http://selenium-python.readthedocs.org/
I tried the following bit of code which is there on the website
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
When I run this program, a Firefox instance opens but never loads the page. check snapshot
This is what I have received in the output console
C:\Users\Gauss\Desktop>python test.py
Traceback (most recent call last):
File "test.py", line 4, in <module>
driver = webdriver.Firefox()
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.egg\selenium\webdriver\firefox\webdriver.py", line 78, in __init__
self.binary, timeout)
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.egg\selenium\webdriver\firefox\extension_connection.py", line 49, in __init__
self.binary.launch_browser(self.profile)
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "D:\Python\Python35\lib\site-packages\selenium-2.50.0-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py", line 106, in _wait_until_connectable
% (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: C:\Users\Gauss\AppData\Local\Temp\tmpkpjhnhpb If you specified a log_file in the FirefoxBinary constructor, check it for details.
Could someone please suggest a solution to this issue?
Note: This issue is on my office pc and the same code works fine on my home pc. So some issue with Firefox maybe.
Based on your comments, it looks like the version of Firefox you have is not yet supported by python driver. Currently they support up to v. 38, you have 44.
Related
I am following a tutorial of a video on youtube about selenium and I got to this point
This is my code and it works fine until it gives you this massive error of:
Traceback (most recent call last):
File "D:\pythonProject\webscraping.py", line 17, in <module>
search.send_keys(Keys.RETURN)
File "C:\Users\Han\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 602, in send_keys
'value': keys_to_typing(value)})
File "C:\Users\Han\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 773, in _execute
return self._parent.execute(command, params)
File "C:\Users\Han\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "C:\Users\Han\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unexpected command response
(Session info: chrome=103.0.5060.53)
....
Here is the code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
service=Service("C:\Program Files (x86)\chromedriver.exe")
driver = webdriver.Chrome(service=service)
driver.get("https://www.techwithtim.net/")
print(driver.title)
search = driver.find_element(By.NAME, 's')
search.send_keys("test")
search.send_keys(Keys.RETURN)
driver.quit()
I've been getting the same error as well. There seems to be an issue with Chromedriver 103. Your options are to wait for the new version, or to download Chrome Beta and use Chromedriver 104 with it.
A lot of people have also said to downgrade and use 102 instead.
Here's a link to a thread where others have reported the same problem:
https://github.com/SeleniumHQ/selenium/issues/10799
(//input[#name='s'])[2]
There's actually a second input with that value hidden use the above xpath.
I am using selenium with python and have downloaded the chromedriver for my windows computer from this site. After downloading the zip file, I unpacked the zip file to my downloads folder. Then I add the path to the the Environment Variable "Path".
I want to get information from the site, but when I run code, I get this error and comletely don't understand what is it about.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
browser = webdriver.Chrome(ChromeDriverManager().install())
url = 'any_url'
browser.get(url)
if browser.find_element_by_id("yearlist_1").get_attribute("type") == "checkbox":
print("Element is a checkbox")
else:
print("Element is not a checkbox")
The error:
*'reg' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
File "C:/Users/miair/Python/script_gks/code_for_ticks.py", line 4, in <module>
browser = webdriver.Chrome(ChromeDriverManager().install())
File "C:\Program Files\Python37\lib\site-packages\webdriver_manager\chrome.py", line 28, in install
driver_path = self.download_driver(self.driver)
File "C:\Program Files\Python37\lib\site-packages\webdriver_manager\manager.py", line 36, in download_driver
driver_version, is_latest = self.__get_version_to_download(driver)
File "C:\Program Files\Python37\lib\site-packages\webdriver_manager\manager.py", line 27, in __get_version_to_download
return self.__get_latest_driver_version(driver), True
File "C:\Program Files\Python37\lib\site-packages\webdriver_manager\manager.py", line 21, in __get_latest_driver_version
return driver.get_latest_release_version()
File "C:\Program Files\Python37\lib\site-packages\webdriver_manager\driver.py", line 58, in get_latest_release_version
self._latest_release_url + '_' + chrome_version(self.chrome_type))
File "C:\Program Files\Python37\lib\site-packages\webdriver_manager\utils.py", line 114, in chrome_version
.format(cmd)
ValueError: Could not get version for Chrome with this command: reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version*
Sorry, I am very new to Python, but if somebody could help, I'll be very pleased and thankful.
I solved problem. I don't understand why I've hadn't think of this solution before - all you need to do is to write the path of your chromedriver (only if you have a correct version)
browser = webdriver.Chrome('path')
important to know for people searching for the same error and ending here. chrome needs to have started at least once to generate the reg key in windows.
I suspect that you are using a selenium web-driver that is not matching your chrome driver version.
you can update your chrome using the following link:
chrome://settings/help
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
browser = webdriver.Firefox(executable_path=r'/usr/bin/firefox')
browser.get("http://google.com/")
Ubuntu 16 LTS user here.How to fix this empty window issue after I enter url and is no loaded page there.
Output:
> > Traceback (most recent call last): File "/home/pc/PycharmProjects/calculator/test.py", line 781, in <module>
> browser = webdriver.Firefox(executable_path=r'/usr/bin/firefox') File
> "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py",
> line 164, in __init__
> self.service.start() File "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
> line 98, in start
> self.assert_process_still_running() File "/home/pc/PycharmProjects/calculator/venv/lib/python3.5/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/firefox unexpectedly exited. Status code was: 0
You need to provide geckodriver path not firefox. Check your firefox browser version and you can download compatible geckodriver from Here
browser = webdriver.Firefox(executable_path="path of geckodriver")
Sample code
browser = webdriver.Firefox(executable_path="/Users/username/Location/geckodriver")
browser.get("https://google.com")
You can add the path to your webdriver in the PATH system variable
export PATH=$PATH:/path/to/driver/firefox-driver
Add it to /home//.profile file to make it permanent.
Then you dont need executable_path=''
I'm currently in CH11 from the "Automate the Boring Stuff with Python" book and I'm going over the Selenium module. I'm trying to move to the end of a page but I'm getting some problems. I also tried to look similar problems in this site and tried the solutions suggested without success unfortunately. Here's my code, when I type it into the IDLE Shell:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser= webdriver.Firefox()
browser.get('http://nostarch.com')
htmlElem= browser.find_element_by_tag_name('html')
type(htmlElem)
<class 'selenium.webdriver.firefox.webelement.FirefoxWebElement'>
htmlElem.send_keys(Keys.END) # Error
Exception -:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
htmlElem.send_keys(Keys.END)
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 347, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 494, in _execute
return self._parent.execute(command, params)
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not visible
Apparently the html element is not visible? I don't understand how so since it seems to locates the html element just fine as seen on the code without any problems but the Key.ENTER is where I'm getting the error.
Any help would be appreciated.
Just tested the following with Chrome driver and it works (It should also work with Firefox):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('http://nostarch.com')
body_elem = browser.find_element_by_tag_name('body')
body_elem.send_keys(Keys.END)
This question already has an answer here:
How to fix WebDriverException: The browser appears to have exited before we could connect? [duplicate]
(1 answer)
Closed 7 years ago.
I have a simple python script that works fine on my local machine. But if I try to run it on my vps I get an error:
Traceback (most recent call last):
File "test.py", line 15, in <module>
browser = webdriver.Firefox(profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-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.
And here is the script:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('permissions.default.image', 2)
# Set all new windows to open in the current window instead
profile.set_preference('browser.link.open_newwindow', 1)
browser = webdriver.Firefox(profile)
browser.get('http://www.google.com/')
html = browser.page_source
print html
browser.close()
Since there is no GUI for the vps is that what is causing the error?
You have to use xvfb package to run webdriver correctly.
usr/bin/xvfb-run /usr/bin/python myfile.py
Check This link for more detail