SeleniumLibrary
SeleniumLibrary copied to clipboard
'Page Should Contain Button' & 'Click Button' can not find HTML button
HTML button:
<button class="foo" type="bar" data-ember-action="123">
<i class="icon-arrow-right"></i>
Logout
</button>
Accessing this button from RF with the following code does not work:
***keywords***
Log Off And Close Browser
Page Should Contain Button Logout
Click Button Logout
Login Page Should Be Open
Close Browser
I´m quite sure that the keyword worked properly before the devs added
<i class="icon-arrow-right"></i>
to the button.
Here´s the output of Robot log file: Page Should Contain Button | Logout
DEBUG POST http://sut_ip/hub/session/123/elements {"using": "xpath", "sessionId": "123", "value": "//input[(@id='Logout' or @name='Logout' or @value='Logout' or @src='Logout' or @src='https://sut_url/Logout')]"}
BTW: Here I wonder why the keyword 'Page Should Contain Button' looks up in <input>
tag?
DEBUG POST http://sut_ip/hub/session/123/elements {"using": "xpath", "sessionId": "123", "value": "//button[(@id='Logout' or @name='Logout' or @value='Logout' or normalize-space(descendant-or-self::text())='Logout')]"}
FAIL Page should have contained button 'Logout' but did not
DEBUG Traceback (most recent call last): File "<string>", line 2, in page_should_contain_button File "C:\Python27\lib\site-packages\Selenium2Library\keywords\keywordgroup.py", line 15, in _run_on_failure_decorator return method(*args, **kwargs) File "C:\Python27\lib\site-packages\Selenium2Library\keywords\_formelement.py", line 332, in page_should_contain_button self._page_should_contain_element(locator, 'button', message, loglevel) File "C:\Python27\lib\site-packages\Selenium2Library\keywords\_element.py", line 858, in _page_should_contain_element raise AssertionError(message)
Click Button | Logout
I cross checked it in pure Selenium. This were my findings:
Is it possible that normalize-space()
somehow breaks the keyword(s)?
You have found at least two possible issues.
- The
Page Should Contain Button
andClick Button
don't use internally same xpath selector to find the button. This explains many complaints in the user group mailing list. -
normalize-space()
should not break anything and I use it a lot in my own testing. But I have not used exactly that syntax, so we need to verify why that syntax did not work.
Thanks from detailed analysis.
As a workaround you can use the Page Should Contain Element
and Click Element
keywords.
This element does not have a locator to identify it.
If you want to use this keywords this button needs to have an id or name to works. Example: locator by id: ...button id="Logout" class="foo" type="bar" data-ember-action="123"...
locator by name: ...button name="Logout" class="foo" type="bar" data-ember-action="123"...
ref: http://robotframework.org/Selenium2Library/doc/Selenium2Library.html