Python Selenium chromedriver : StaleElementReferenceException: Message: stale element reference: element is not attached to the page document .. some notes

When switching to using chromedriver and away from PhantomJS these messages were everywhere. They are a bit misleading.

StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

A lot of these can be fixed with waiting for the element to fully load before trying to access it. In the cases we ran into, almost all stale element references were due to javascript not fully loaded before the element could be accessed.

A simple time.sleep() would immediately fix it. Then we searched for more elegant ways to wait for the element.

The error message mentions stale element which one might associate with old and outdated, but in fact it’s actually too new.

Python Selenium Chrome driver : element is not clickable at point. Other element would receive the click (Solved)

This is a common issue with Chrome Driver. There are a bunch of discussion boards where requests are made to have this fixed but for some reasons Chrome developers are stubborn in not fixing it. How about they ask their customers what they would want!

Anyways, this helps. It moves the element into view. For a set of tests we had that worked fine with PhantomJS (too bad dev was discontinued) and Firefox, errors came up with Chrome. This was along the lines of : element is not clickable at point. Other element would receive the click.

Before the element that has that error, you could input this line (change the element please, unless you are clicking on Good Morning! text:

self.driver.execute_script("arguments[0].scrollIntoView();", self.driver.find_element_by_link_text('Good Morning!'))

That fixed it for us and did not break PhantomJS and/or Firefox compatibility.

HDD to SSD slow transfer using SATA to USB3 cable (somewhat solved)

As just about everyone else I am switching my hard drive to an SSD.
Purchased the Samsung 850 EVO 1TB 2.5-Inch SATA III Internal SSD (MZ-75E1T0B/AM). That all arrived well.
Also then bought a Sabrent cable, SATA to USB 3.0 (under $10).
The problems started occurring when I was cloning the drives using Samsung’s Data Migration Software.
Note : My existing drive (SATA II internal) has been showing errors when using various HD inspection tools so that is one possible cause of slowness. It was also becoming very slow during general operation which was the reason to switch to SSD.

  1. I was cloning approximately 670GB of data on 931TB drive
  2. On the initial attempt transfer rate was 1MB/s. The estimate was 300+ hours to complete so I aborted that.
  3. I then plugged the cable into the USB 2.0 port. That produces speeds around 25MB/s but still very slow
  4. Then I switched back to plugging it into the USB 3.0 port. This time, speeds got up to 59MB/s and the promised completion time was under 4 hours which is acceptable. However, half way through it slowed down to 1MB/s and I had to cancel.
  5. Following some online research I proceeded to: disable Microsoft real time virus protection, disconnected the network drives that were mounted and also disconnected the Ethernet cable from the PC completely diabling networking.
  6. That worked. Speeds were again near 60MB/s and the clone took under 3.5 hours. Success.

I do know that USB 3.0 should provide higher transfer rates, but at this point I was just happy to get this done. I did not have time to investigate more.

PyCharm 2017.3 causing issues when nosetests runs into errors (Python Selenium)

After upgrading to PyCharm 2017.3 I am not able to run my tests properly. Any time an error is encountered, the test case does not fail and move on, it just stops executing. Downgrading to PyCharm 2017.2.4 resolves the problem.

Here are the errors I get:

jb_nosetest_runner.py", line 17, in
nose.main(addplugins=[TeamcityReport()])

... etc etc etc .....

in formatError
ec, ev, tb = err
TypeError: 'NoneType' object is not iterable

Selenium Python configuration for Chrome in headless mode

Here is what worked for me related to Chrome in headless mode:

First import a few modules:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

Then set the driver:

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
self.driver = webdriver.Chrome(executable_path="C:/webdriver/chromedriver.exe",chrome_options=chrome_options)

Please make sure to change the binary location to where Chrome is installed on your system. Also, you will need the latest chromedriver.exe executable (downloadable from here : https://sites.google.com/a/chromium.org/chromedriver/.). You will need to put its location in the executable_path. You will need Selenium 3.8.0 approximately as well.

REST Client for Visual Studio Code is nice

Get it from the extension manager in VS Code: REST Client by Huachao Mao

GitHub fun is here:
https://github.com/Huachao/vscode-restclient

I wanted to include some examples, but then I saw the documentation in VS Code for this extension and it’s very good. Just scroll through the Details tab and get the instructions how to use. It’s quite simple, including, something like GET https://httpbin.org/uuid for a simple get.

Selenium Python configuration for Firefox in headless mode

This worked for me :

Import few modules:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FFOptions

then set the driver:

options = FFOptions()
options.add_argument('--headless')
self.driver = webdriver.Firefox(firefox_options=options)

Please note that you have to have the latest FF (57 will do) and selenium 3.8.0 approximately.

Errors when starting Blender on Windows, related to PYTHONPATH : Solved

I needed to document this here as every new release I run into the same issue when starting Blender. It crashes on start. Found the solution on the net:

Create a batch file to start Blender. I named mine blender.bat (quite original).

Contents of the file :

set PYTHONPATH=""
cd C:\Program Files\Blender Foundation\Blender\
start blender.exe

Adjust your install location as needed. Then just save and double click to start. Voila!

To connect to a Mongo 3.x DB you need to use Mongo 3.x client or Mongo 3.x compatible UI

I was just setting up Mongo database on a CentOS server. Tried to connect from a remote Ubuntu machine and failed. Tried to connect with older copy of MongoVue and failed. Tried everything, setting mongod.conf to all kinds of values, changing iptables, creating and recreating DBs, admin and other users. No luck. Wasted a day.

Then only thanks to this post I learned that it might be due to incompatibility of versions.
https://stackoverflow.com/questions/31091121/failed-connection-in-mongovue#comment50198839_31091121

I tried to connect from a machine that had Mongo 3.x installed and … success. I also installed Robo 3T from www.robomongo.org and it worked like a charm as well. Might save someone time.

Here are some messages that I was getting when trying to connect from old version of MongoVue:

Unable to connect to server asdfasdffake.com:27017: Object reference not set to an instance of an object..
Type: MongoDB.Driver.MongoConnectionException
Stack:    at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect(TimeSpan timeout, ReadPreference readPreference)
   at MongoDB.Driver.MongoServer.Connect(TimeSpan timeout)
   at MongoDB.Driver.MongoServer.Connect()
   at MangoUI.MMongo.QSDlL5xzK686iCExThO(Object )
   at MangoUI.MMongo.Open(Boolean mustWrite)
   at MangoUI.MMongo.Open()
   at MangoUI.ComNavTree.eocHiDskdDq1GPOj7uu(Object )
   at MangoUI.ComNavTree.ExpandMe(MTreeNode expand)
   at MangoUI.ComNavTree.tree_BeforeExpand(Object sender, TreeViewCancelEventArgs e)


Object reference not set to an instance of an object.
Type: System.NullReferenceException
Stack:    at MongoDB.Driver.MongoServerInstance.RefreshStateAsSoonAsPossible()
   at MongoDB.Driver.Internal.MongoConnection.HandleException(Exception ex)
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(BsonBuffer buffer, Int32 requestId)
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message)
   at MongoDB.Driver.Operations.CommandOperation`1.Execute(MongoConnection connection)
   at MongoDB.Driver.MongoServerInstance.RunCommandAs[TCommandResult](MongoConnection connection, String databaseName, IMongoCommand command)
   at MongoDB.Driver.MongoServerInstance.Ping(MongoConnection connection)
   at MongoDB.Driver.MongoServerInstance.Connect()
   at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect(TimeSpan timeout, ReadPreference readPreference)




Connection was refused
Unable to connect to server asdfasdffake.com:27017: Invalid credential for database 'test_db'..
Type: MongoDB.Driver.MongoConnectionException
Stack:    at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect(TimeSpan timeout, ReadPreference readPreference)
   at MongoDB.Driver.MongoServer.Connect(TimeSpan timeout)
   at MongoDB.Driver.MongoServer.Connect()
   at MangoUI.MMongo.QSDlL5xzK686iCExThO(Object )
   at MangoUI.MMongo.Open(Boolean mustWrite)
   at MangoUI.MMongo.Open()
   at MangoUI.MConnection.get_IsValid()
   at MangoUI.WinConnect.SCOjR9kYRPerNNngykW(Object )
   at MangoUI.WinConnect.btnTest_Click(Object sender, EventArgs e)


Invalid credential for database 'test_db'.
Type: MongoDB.Driver.MongoAuthenticationException
Stack:    at MongoDB.Driver.Communication.Security.MongoCRAuthenticationProtocol.Authenticate(MongoConnection connection, MongoCredential credential)
   at MongoDB.Driver.Communication.Security.Authenticator.Authenticate(MongoCredential credential)
   at MongoDB.Driver.Communication.Security.Authenticator.Authenticate()
   at MongoDB.Driver.Internal.MongoConnection.Open()
   at MongoDB.Driver.Internal.MongoConnection.GetNetworkStream()
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(BsonBuffer buffer, Int32 requestId)
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message)
   at MongoDB.Driver.Operations.CommandOperation`1.Execute(MongoConnection connection)