Waiting for a page to load while writing selenium scripts is pretty straightforward using the
selenium.WaitForPageToLoad("timeout") timeout is time in millisecond.
Sometimes using this command doesn't work, especially when you the whole page is not loaded or reloaded but a popup is loaded in a div on the page. In situation like this i would used the
selenium.WaitForCondition("ScriptToReturnwhich ReturnTrue OrFalse", "timeout");
e.g. of scripts would be
selenium.WaitForCondition(selenium.browserbot.get CurrentWindow().document
.getElement ById('idOfElement ToBelocated')!=null", "60000");
This has always worked well for well until today, i had a special case where the element that i needed to wait for it to load was inside an IFrame, which is loaded within a parent page. Using the Wait for condition as above kept timing out as the Javascript could not access the IFrame.
what worked for me after several hours of trying is:
selenium.WaitForCondition("selenium.browserbot.getCurrent Window()
.frames['Name Of IFrame'].document.get Element ById
'idOfElement ToBelocated')!= null", "60000");
This brilliantly eliminated my nightmare .......
Comments are welcome
My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit
http://samueladesoga.wordpress.com
and update your bookmarks.
Showing posts with label DOM. Show all posts
Showing posts with label DOM. Show all posts
Wednesday, 25 February 2009
Saturday, 31 January 2009
Need to get a value of an attribute using selenium
I was in this situation when i needed to get the value of an html attribute and i found the selenium.getattribute very handy .....
Okay the scenario was such that there was an element which is collapsible on the page and the only attibute for that element that indictated the status of the collapsible element was the 'Class'. when the element was collapsed, the value of the class attribute was 'asleep' and when the element was expanded, the value of the class atttribute was 'awake'.
The script used to determine the status of this element is
Okay the scenario was such that there was an element which is collapsible on the page and the only attibute for that element that indictated the status of the collapsible element was the 'Class'. when the element was collapsed, the value of the class attribute was 'asleep' and when the element was expanded, the value of the class atttribute was 'awake'.
The script used to determine the status of this element is
selenium.GetAttribute("elementLocator@nameofAttribute");
so if the id of my element is FundingClass and the attribute we are interested in is the 'Class'
The selenium code will be
selenium.GetAttribute("FundingClass@Class");
Hope this helps someone .....
Tuesday, 23 December 2008
Using selenium.GetEval(script)to execute Javascript
The task at hand was to navigate through the DOM of a particular webpage and check the
style.display attribute of an object or element if you prefer. There are two elements on this page that displayed either success or failure messages.(msgSuccess and msgFailed)
For perfomance reasons, if previously a successful message was displayed and subsequently the you get a failure message, what the developers of the page did was to amend the style.display attribute.
<span style="display: none;" id="msgSuccess" class="MyMsgSuccess">
The HTML code above implies the element 'msgSuccess' would not be displayed
<span style="" id="msgSuccess" class="MyMsgSuccess">
In the second case, the msg success would be displayed ....
The problem i encountered was, sometimes i would have
< span style="display: none;" id="msgSuccess" class="MyMsgSuccess" > Operation Successful </span >
If i do a selenium.GetText("msgSuccess"), i get the text returned even though the style.display is set to none. Hence the need for the Selenium.GetEval to check the value of the style.display attribute as that seem as a true test for the web page
I have done:
const string script = "document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);
The above script failed as selenium was executing the javascript in the selenium console and not on the Application under test (AUT)
and searching the internet got me doing:
const string script = "selenium.browserbot.getCurrentWindow().document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);
This way i got the javascript to be run on the Application under test ....
style.display attribute of an object or element if you prefer. There are two elements on this page that displayed either success or failure messages.(msgSuccess and msgFailed)
For perfomance reasons, if previously a successful message was displayed and subsequently the you get a failure message, what the developers of the page did was to amend the style.display attribute.
<span style="display: none;" id="msgSuccess" class="MyMsgSuccess">
The HTML code above implies the element 'msgSuccess' would not be displayed
<span style="" id="msgSuccess" class="MyMsgSuccess">
In the second case, the msg success would be displayed ....
The problem i encountered was, sometimes i would have
< span style="display: none;" id="msgSuccess" class="MyMsgSuccess" > Operation Successful </span >
If i do a selenium.GetText("msgSuccess"), i get the text returned even though the style.display is set to none. Hence the need for the Selenium.GetEval to check the value of the style.display attribute as that seem as a true test for the web page
I have done:
const string script = "document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);
The above script failed as selenium was executing the javascript in the selenium console and not on the Application under test (AUT)
and searching the internet got me doing:
const string script = "selenium.browserbot.getCurrentWindow().document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);
This way i got the javascript to be run on the Application under test ....
Labels:
DOM,
Javascripts,
QA,
selenium,
testing,
Web Application
Subscribe to:
Posts (Atom)