Pages

Search This Blog

Thursday, May 20, 2010

How to make selenium to wait for an element every second

Sometimes waitForPageToLoad() and pause fails then to handle this condition we just need to wait for an element we are waiting to load on the page. Once its loaded our execution should proceed.


boolean Condition = false;
for (int second = 0; second < 60; second++) {
try {

if ((selenium.isElementPresent("//a[@id='overridelink']"))) {
selenium.click("//a[@id='overridelink']");
Condition = true;
break;
selenium.waitForPageToLoad(MAX_WAIT_TIME_IN_MS);

}

}
catch (Exception ignore) {
}
pause(1000);
}
assertTrue(Condition);

How to compare two variables in selenium

We can compare two variable and store the result as Boolean (true or false ) in a Boolean variable. Using javascript we can compare

<tr>
<td>store</td>
<td>5</td>
<td>a</td>
</tr>
<tr>
<td>store</td>
<td>2</td>
<td>b</td>
</tr>
<tr>
<td>store</td>
<td>javascript{var bool=(storedVars['a']==storedVars['b']);bool;}</td>
<td>bool</td>
</tr>