This project has moved. For the latest updates, please go here.
2
Vote

Selenium Auto completion

description

I'm a QA intern and new to a python. We using selenium for our testing and I'm trying to move all code from C# to Python. Most of the QA team uses Visual Studio 2012 and I've been designated to research/investigate on how Python Selenium would benefit what we already have. I was able to setup everything thats on tutorial
https://selenium-python.readthedocs.org/getting-started.html
except autocompletion of custom package selenium thats on C:\Python27\Lib\site-packages\selenium.
  1. Autocompletion works on first level: self.driver.
  2. self.driver.find_element_by_class_name("loginTxt") should return WebElement object
  3. WebElement object suppose to have send_keys and other WebElement methods
  4. However when I try to Ctrl+Space it only show some default object methods.
When I hard code and run it works. However autocompletion works only on first level objects. I don't know if its Python specific problem or if there is a workaround.

self.driver.find_element_by_class_name("loginTxt").send_keys(Keys.RETURN)

Thanks.

comments

Zooba wrote Dec 15, 2014 at 10:16 PM

It may be that find_element_by_class_name isn't clear enough about what type it returns for our code analyser to figure it out automatically. This can happen easily in Python if the type isn't known until runtime or it's selected through some indirect means like getattr() or similar.

We don't have a good workaround right now, though we are always considering ideas. What you can do is force a certain type on a variable by asserting that it is that type:
login_txt = self.driver.find_element_by_class_name("loginTxt")
assert isinstance(login_txt, WebElement)
login_txt.
This has a runtime effect as well, so it's fairly invasive, but we do currently recognise this pattern and will provide better completions.

nowakgrz wrote Mar 6 at 8:05 AM

My team have the same problem. We are using VS mainly for collaboration with other teams (TFS, TFVS) but writing Selenium tests in python here is quite difficult. I'm personally using PyCharm with it's incredible auto completion and copy-paste code to VS when everything is working.
Is it possible for you to reconsider fixing that issue with IntelliSense and python?

crwilcox wrote May 11 at 4:33 AM

This isn't actively monitored by the team anymore.
https://github.com/Microsoft/PTVS