Get Text in Sel2Lib not working
My xml goes something like the attached file .
I need to get this value '20'. Hence used "Get Text" keyword in robot. It works well with the machine installed with SeleniumLibrary. I just don't get the value with Selenium2Library. I get a blank return . Please help.
The xpath I used is : ${text} Get Text xpath=//div[div[@id='idDiv']]//ul[@id='form:dsaidItems']/li[2]
Is the element visible? If the element is not visible, the underlying selenium library will return empty. This is the way the selenium works and there is nothing we can change in the Selenium2Library side.
Yes the element is visible and very much working for SeleniumLibrary. It just returns blank in case of Selenium2Library.
Are you sure that the selector is unique and points to a right element? Example if you are Firefox user FireBug and FirePath are excellent tools for checking the selectors.
Also what browser and browser version you are using?
I use Firefox v 38 . I am sure about the selector.
There might be some differences how the two libraries differ. Also their supporting libraries, mainly selenium, is totally different things.
If the element is hidden or doesn't contain text the underlying Selenium Webdriver returns empty (Python None if recall correctly). If the element is not found, then error should be raised by the Selenium2Library.
In Selenium2Library if there are multiple elements matches to the selector, then only the first found match is used. Then if the selector is not unique, the wrong element text is returned.
Because the above reasons, the valid selector in SeleniumLibrary may return different results when using Selenium2Library. Therefore it would be good to double check the selector and make sure it is unique.
Also this could be a timing issue. If the page is loaded or content is changed dynamically, before the Get Text is used it could explain why empty is returned. If this is the case, polling that page is fully loaded is needed before the Get Text can be used. For a quick hack, simple sleep would prove is this the reason.
The XML.txt you did attached, it was from the DOM and not from the HTML source. The DOM is the only relevant matter in case of the Selenium Webdriver and now days, there should not be any reason to look the HTML source.
As a last thing, the SeleniumLibrary has, at least one, advantage over the Selenium2Library. It is the support for Flex applications. If your app is using Flex, then it could explain the difference between the results.
There has not been activity for this issue for long time and we are planning to close the old issues if they are not anymore valid ones. If you feel that this is still valid issue, could you send an update. If update is not received in a month, we will assume that this is not anymore an issues and we will close this issue.
Hi,
Even i face the same issue. In-spite of adding wait like 'Wait Until Page Contains Element', it didn't fetch the element text. I have used this statement just above the line where I am fetching the text. Eg: Wait Until Page Contains Element ${elementsInList} timeout=120 ${textValue} Get Text ${elementsInList}
Could you open a new issue