SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Get Windows XXX / Select Window Breaks on IE8 / Win 7, FF works fine

Open adwu73 opened this issue 15 years ago • 7 comments

When I try to use a simple test, I found that Get Windows Names / Titles / Identifies all breaks on IE8 / Win7, while FF works fine. The error is "TypeError: object of type 'WebElement' has no len()". Can someone help to look into this?

Select Window already fail with same error messages, I suspect the root cause is the same.

adwu73 avatar Nov 30 '11 07:11 adwu73

16:08:51.334 DEBUG Traceback (most recent call last): File "C:\Python27\lib\site-packages\robot\running\timeouts.py", line 85, in run return runner.get_result() File "C:\Python27\lib\site-packages\robot\utils\robotthread.py", line 37, in run self._result = self.runnable() File "C:\Python27\lib\site-packages\robot\utils\robotthread.py", line 28, in self.runnable = lambda: runnable((args or ()), *(kwargs or {})) File "", line 2, in get_window_titles File "C:\Python27\lib\site-packages\Selenium2Library\keywords\keywordgroup.py", line 12, in _run_on_failure_decorator return method(_args, *_kwargs) File "C:\Python27\lib\site-packages\Selenium2Library\keywords_browsermanagement.py", line 142, in get_window_titles return self._log_list(self._window_manager.get_window_titles(self._current_browser())) File "C:\Python27\lib\site-packages\Selenium2Library\locators\windowmanager.py", line 23, in get_window_titles return [ window_info[3] for window_info in self._get_window_infos(browser) ] File "C:\Python27\lib\site-packages\Selenium2Library\locators\windowmanager.py", line 92, in _get_window_infos window_infos.append(browser.get_current_window_info()) File "C:\Python27\lib\site-packages\Selenium2Library\webdrivermonkeypatches.py", line 26, in get_current_window_info for att in atts ]

adwu73 avatar Nov 30 '11 08:11 adwu73

Hi there, I did more test today, and find some temp solutions, I will try to test in the real app tomorrow. Now the work around works for my test app. Since I don't really understand python code, I hope someone can help me out here.

For the trace above, I found out the code in trouble is this line in webdrivermonkeypatches.py around line 26: atts = [ att if att is not None and len(att) else 'undefined' for att in atts ]

I don't understand the logic here, it seems like some kind of error proof code here. When I tried to remove this two lines completely, my IE test case succeeded.

I add an Execute Javascirpt | return [ window.id, window.name, document.title, document.location ]; into my test script, I found that the IE and Firefox return is different, I am not sure whether the differences caused the trouble:

Here is the IE output: None, '', u'Login', <selenium.webdriver.remote.webelement.WebElement object at 0x027991B0>

Here is the FireFox output: [None, '', u'Login', {u'search': '', u'assign': u'function assign() {\n [native code]\n}', u'hash': '', u'hostname': u'zdiles.chaosnet.org', u'replace': u'function replace() {\n [native code]\n}', u'reload': u'function reload() {\n [native code]\n}', u'host': u'zdiles.chaosnet.org', u'href': u'http://zdiles.chaosnet.org/index.php', u'pathname': u'/index.php', u'protocol': u'http:', u'port': ''}]

I hope this can be helpful for someone that can really fix this issue from the root, tks!!!

adwu73 avatar Dec 01 '11 12:12 adwu73

The cause appears to be triggered by document.location parameter in the execute_script call on line 24. atts = self.execute_script("return [ window.id, window.name, document.title, document.location ];")

IE driver returns a web element object but Firefox driver returns a dictionary:

IE driver returns [None, '', u'Page Title', <selenium.webdriver.remote.webelement.WebElement object at 0x01807EB0>]

Firefox driver returns [None, '', u'Page Title', {u'search': '', u'assign': u'function assign() {\n [native code]\n}', u'hash': '', u'hostname': u'host.domain', u'replace': u'function replace() {\n [native code]\n}', u'reload': u'function reload() {\n [native code]\n}', u'host': u'host.domain', u'href': u'http://qtst.atpco.org/fmhome/login.jsp', u'pathname': u'/path/to/file.html', u'protocol': u'http:', u'port': ''}]

Since "Select Window" keyword offers locator options for name, title & url can you change line 24 to: atts = self.execute_script("return [ window.id, window.name, document.title, document.url ];")

This tested ok for me on IE & Chrome and trusting this reference http://www.w3schools.com/jsref/prop_doc_url.asp it appears document.url is supported by all browser versions

Hope this helps

retailernet avatar Mar 22 '12 14:03 retailernet

tks I will modify the code and give a try

adwu73 avatar Mar 23 '12 03:03 adwu73

I have tested the fix, it works for my simple test case, not sure this change other behaviours of the system, I will test this fix in real test code next week

adwu73 avatar Mar 24 '12 01:03 adwu73

I have also observed this issue on IE9/Win7 and can confirm that the fix suggested by retailernet fixes this issue.

stevejefferies avatar Jul 11 '12 13:07 stevejefferies

Fix released under version 1.1 Selenium2Library.

emanlove avatar Nov 06 '12 22:11 emanlove