What code creates the selenium error “WebDriverException: Message: TypeError: rootNode is null”? - selenium

In this question I am not asking to help solve this problem (that would be too much asked). I am asking where I can find the code that actually generated that error message.
The error massage occurs when running with a firefox webdriver with python-selenium.
As far as I know the first part
WebDriverException: Message:
is generated by selenium itself. But where does the other part come from?
TypeError: rootNode is null
Is it from firefox itself? geckodriver? Marionette? Something else?
What source code do I need to check to find the following character string?
TypeError: rootNode is null
Full stacktrace:
...
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 934, in save_screenshot
return self.get_screenshot_as_file(filename)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 911, in get_screenshot_as_file
png = self.get_screenshot_as_png()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 943, in get_screenshot_as_png
return base64.b64decode(self.get_screenshot_as_base64().encode('ascii'))
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 953, in get_screenshot_as_base64
return self.execute(Command.SCREENSHOT)['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: TypeError: rootNode is null
Software used:
Firefox: Mozilla Firefox 57.0.3
geckodriver: 0.19.1
nosetests: version 1.3.7
selenium: 3.8.0

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 !!!

I keep getting an error saying "Message: invalid session id" Can someone help me out please [duplicate]

I'm writing some code using Selenium, and at one point I make 7 requests, all to different websites. For the first one, this works fine. However, for others, I get a session ID error. I think that my browser is configured correctly, as I do get results from the first website. I have tried to put a WebDriverWait in between the requests, but to no avail. I think the websites might be blocking my requests. Does anyone have any idea how to solve this problem?
I'm sorry if this is something stupid or if I'm doing anything wrong, I'm quite new ^^
Thanks in advance!
Traceback (most recent call last):
File "/home/cena/PycharmProjects/Frikandelbroodje/main.py", line 56, in <module>
dirk_price = get_price(dirk_url, dirk_classname)
File "/home/cena/PycharmProjects/Frikandelbroodje/main.py", line 44, in get_price
browser.get(url)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid session id
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Linux 4.15.0-50-generic x86_64)
invalid session id
The invalid session ID error is a WebDriver error that occurs when the server does not recognize the unique session identifier. This happens if the session has been deleted or if the session ID is invalid.
A WebDriver session can be deleted through either of the following ways:
Explicit session deletion: A WebDriver session is explicitly deleted when explicitly invoking the quit() method as follows:
Code Block:
from selenium import webdriver
from selenium.common.exceptions import InvalidSessionIdException
driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
print("Current session is {}".format(driver.session_id))
driver.quit()
try:
driver.get("https://www.google.com/")
except Exception as e:
print(e.message)
Console Output:
Current session is a9272550-c4e5-450f-883d-553d337eed48
No active session with ID a9272550-c4e5-450f-883d-553d337eed48
Implicit session deletion: A WebDriver session is implicitly deleted when you close the last window or tab invoking close() method as follows:
Code Block:
driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
print("Current session is {}".format(driver.session_id))
# closes current window/tab
driver.close()
try:
driver.get("https://www.google.com/")
except Exception as e:
print(e.message)
Console Output:
Current session is a9272550-c4e5-450f-883d-553d337eed48
No active session with ID a9272550-c4e5-450f-883d-553d337eed48
Conclusion
As the first one request works fine but for others you get a session ID error most possibly the WebDriver controled Web Browser is getting detected and hence blocking the next requests.
There are different reasons for the WebDriver controled Web Browser to get detected and simultaneously get blocked. You can find a couple of detailed discussion in:
How does recaptcha 3 know I'm using selenium/chromedriver?
Selenium and non-headless browser keeps asking for Captcha
I got this error message because I was running Selenium in docker and I hadn't mounted enough swap memory, so it would crash after just a few pages.
To fix this, I used the same docker command, but added -v /dev/shm:/dev/shm after docker run.
If you had this
docker run -d -p 5901:5900 -p 127.0.0.1:4445:4444 selenium/standalone-chrome
then change to this
docker run -v /dev/shm:/dev/shm -d -p 5901:5900 -p 127.0.0.1:4445:4444 selenium/standalone-chrome
I found this info here, and here.
Browser page crash may leads to InvalidSessionIdException. Selenium says to us: session deleted because of page crash. Check if your browser page still exists when you got your errors.
Here an example of a traceback of this case:
[2021-06-28 15:05:43,787: ERROR/ForkPoolWorker-2] Message: invalid session id
Traceback (most recent call last):
...
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/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: session deleted because of page crash
from tab crashed
(Session info: chrome=83.0.4103.61)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 580, in find_elements_by_class_name
return self.find_elements(by=By.CLASS_NAME, value=name)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 1007, in find_elements
'value': value})['value'] or []
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id
If you want some technical details, take a look at Chromium sources where you can find string session deleted because of page crash.
I had this problem and the reason was that I wrote url in wrong format - not like this, which is correct:
self.driver.get('https://twitter.com')
But this way:
self.driver.get('twitter.com')
Maybe you had the same issue. If not, just check all the links and make sure that all of them are in format of the correct one
in mycase the issue I executed driver.close() then tried to access current_url property of driver which is already closed
this what my wrong code leads to this error message:
url = 'http://localhost:5000/traning'
webpage = driver.get(url)
time.sleep(2)
driver.close()
return driver.current_url
this returns error:
selenium.common.exceptions.InvalidSessionIdException: Message: invalid
session id
and this is solution just save current url and all data in variable before close driver to return this data
driver = setDriver()
url = 'http://localhost:5000/traning'
webpage = driver.get(url)
current_url = driver.current_url
time.sleep(2)
driver.close()
return current_url
Try this:
driver.get('url')
#some code
current_page = driver.current_url
driver.close()
driver.quit()
time.sleep(10)
driver.get(current_page)
After I put driver.close with driver.quit it solve same issue, as you have

org.openqa.selenium.NoSuchSessionException in testng [duplicate]

I'm writing some code using Selenium, and at one point I make 7 requests, all to different websites. For the first one, this works fine. However, for others, I get a session ID error. I think that my browser is configured correctly, as I do get results from the first website. I have tried to put a WebDriverWait in between the requests, but to no avail. I think the websites might be blocking my requests. Does anyone have any idea how to solve this problem?
I'm sorry if this is something stupid or if I'm doing anything wrong, I'm quite new ^^
Thanks in advance!
Traceback (most recent call last):
File "/home/cena/PycharmProjects/Frikandelbroodje/main.py", line 56, in <module>
dirk_price = get_price(dirk_url, dirk_classname)
File "/home/cena/PycharmProjects/Frikandelbroodje/main.py", line 44, in get_price
browser.get(url)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid session id
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Linux 4.15.0-50-generic x86_64)
invalid session id
The invalid session ID error is a WebDriver error that occurs when the server does not recognize the unique session identifier. This happens if the session has been deleted or if the session ID is invalid.
A WebDriver session can be deleted through either of the following ways:
Explicit session deletion: A WebDriver session is explicitly deleted when explicitly invoking the quit() method as follows:
Code Block:
from selenium import webdriver
from selenium.common.exceptions import InvalidSessionIdException
driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
print("Current session is {}".format(driver.session_id))
driver.quit()
try:
driver.get("https://www.google.com/")
except Exception as e:
print(e.message)
Console Output:
Current session is a9272550-c4e5-450f-883d-553d337eed48
No active session with ID a9272550-c4e5-450f-883d-553d337eed48
Implicit session deletion: A WebDriver session is implicitly deleted when you close the last window or tab invoking close() method as follows:
Code Block:
driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
print("Current session is {}".format(driver.session_id))
# closes current window/tab
driver.close()
try:
driver.get("https://www.google.com/")
except Exception as e:
print(e.message)
Console Output:
Current session is a9272550-c4e5-450f-883d-553d337eed48
No active session with ID a9272550-c4e5-450f-883d-553d337eed48
Conclusion
As the first one request works fine but for others you get a session ID error most possibly the WebDriver controled Web Browser is getting detected and hence blocking the next requests.
There are different reasons for the WebDriver controled Web Browser to get detected and simultaneously get blocked. You can find a couple of detailed discussion in:
How does recaptcha 3 know I'm using selenium/chromedriver?
Selenium and non-headless browser keeps asking for Captcha
I got this error message because I was running Selenium in docker and I hadn't mounted enough swap memory, so it would crash after just a few pages.
To fix this, I used the same docker command, but added -v /dev/shm:/dev/shm after docker run.
If you had this
docker run -d -p 5901:5900 -p 127.0.0.1:4445:4444 selenium/standalone-chrome
then change to this
docker run -v /dev/shm:/dev/shm -d -p 5901:5900 -p 127.0.0.1:4445:4444 selenium/standalone-chrome
I found this info here, and here.
Browser page crash may leads to InvalidSessionIdException. Selenium says to us: session deleted because of page crash. Check if your browser page still exists when you got your errors.
Here an example of a traceback of this case:
[2021-06-28 15:05:43,787: ERROR/ForkPoolWorker-2] Message: invalid session id
Traceback (most recent call last):
...
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/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: session deleted because of page crash
from tab crashed
(Session info: chrome=83.0.4103.61)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 580, in find_elements_by_class_name
return self.find_elements(by=By.CLASS_NAME, value=name)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 1007, in find_elements
'value': value})['value'] or []
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id
If you want some technical details, take a look at Chromium sources where you can find string session deleted because of page crash.
I had this problem and the reason was that I wrote url in wrong format - not like this, which is correct:
self.driver.get('https://twitter.com')
But this way:
self.driver.get('twitter.com')
Maybe you had the same issue. If not, just check all the links and make sure that all of them are in format of the correct one
in mycase the issue I executed driver.close() then tried to access current_url property of driver which is already closed
this what my wrong code leads to this error message:
url = 'http://localhost:5000/traning'
webpage = driver.get(url)
time.sleep(2)
driver.close()
return driver.current_url
this returns error:
selenium.common.exceptions.InvalidSessionIdException: Message: invalid
session id
and this is solution just save current url and all data in variable before close driver to return this data
driver = setDriver()
url = 'http://localhost:5000/traning'
webpage = driver.get(url)
current_url = driver.current_url
time.sleep(2)
driver.close()
return current_url
Try this:
driver.get('url')
#some code
current_page = driver.current_url
driver.close()
driver.quit()
time.sleep(10)
driver.get(current_page)
After I put driver.close with driver.quit it solve same issue, as you have

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.