Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use __eq__ it's broken in Selenium. #26

Merged
merged 1 commit into from
Nov 1, 2014

Conversation

tirsen
Copy link
Contributor

@tirsen tirsen commented Sep 9, 2014

If you return a WebElement from a method then you get the following error:

Traceback (most recent call last):
...snip...
File "/Users/tirsen/triposo/devel/triposo3/venv/lib/python2.7/site-packages/holmium/core/pageobject.py", line 211, in wrap
  resp = attr(*args, **kwargs)
File "/Users/tirsen/triposo/devel/triposo3/iosguide/automator.py", line 43, in get_next_version_and_status
  return self.get_next_version_element().text.split(' ')
File "/Users/tirsen/triposo/devel/triposo3/venv/lib/python2.7/site-packages/holmium/core/pageobject.py", line 212, in wrap
  if None == resp:
File "/Users/tirsen/triposo/devel/triposo3/venv/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 351, in __eq__
  if self._id == element.id:
AttributeError: 'NoneType' object has no attribute 'id'

This is because the Selenium WebElement class __eq__ method can't handle being called with None. (I don't think it's implemented correctly.)

It's much safer to check for None like this.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling c079b04 on tirsen:master into 745bc0d on alisaifee:master.

alisaifee added a commit that referenced this pull request Sep 10, 2014
@alisaifee
Copy link
Owner

@tirsen thanks. I changed a test case to reproduce the problem (4f2048c) - and indeed the test case fails without your patch when I run the test locally. However, for some reason its not failing on travis. Could you please also try out that test.

@tirsen
Copy link
Contributor Author

tirsen commented Sep 13, 2014

I can't really run the unit tests. I get the following error:
Traceback (most recent call last):
File
"/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py",
line 331, in run
testMethod()
File "/Users/tirsen/src/holmium.core/tests/bugreports_tests.py", line
163, in test_stale_element_in_wait
driver = get_driver()
File "/Users/tirsen/src/holmium.core/tests/utils.py", line 18, in
get_driver
phantom = webdriver.PhantomJS()
File
"/Users/tirsen/src/holmium.core/venv/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py",
line 50, in init
self.service.start()
File
"/Users/tirsen/src/holmium.core/venv/lib/python2.7/site-packages/selenium/webdriver/phantomjs/service.py",
line 74, in start
raise WebDriverException("Unable to start phantomjs with ghostdriver.",
e)

I've installed phantomjs. Do you have any instructions on how to set
everything up?

On Wed, Sep 10, 2014 at 4:08 AM, Ali-Akber Saifee [email protected]
wrote:

@tirsen https://github.com/tirsen thanks. I changed a test case to
reproduce the problem (4f2048c
4f2048c)

  • and indeed the test case fails without your patch when I run the test
    locally. However, for some reason its not failing on travis. Could you
    please also try out that test.


Reply to this email directly or view it on GitHub
#26 (comment).

@alisaifee
Copy link
Owner

Hi @tirsen. For phantomjs to work all you need is for phantom to be on the PATH. check if which phantomjs returns a valid location. I personally installed it with homebrew.

alisaifee added a commit that referenced this pull request Nov 1, 2014
Don't use __eq__ it's broken in Selenium.
@alisaifee alisaifee merged commit e128c16 into alisaifee:master Nov 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants