How can I test DHTML with Selenium RC?
I'm having problems testing parts of my html pages with Selenium RC. If an element is present in the page and is visible when the page is loaded then there is no problem, Selenium RC can access it and can get its value or write into it (if it's a input), etc.
But if the element is not visible and it is only made visible using javascript, then selenium cannot work with it. For exa开发者_开发百科mple I have 2 divs:
<div id="row2" class="row" onclick="switchTo('row2e');">
<div class="row label">Address</div>
<div class="row data">${user.address}</div>
</div>
<div id="row2e" class="row-edit">
<form id="address-form" name="address-form" method="post" onsubmit="">
<div class="row label">Address-Must be 5-25 letters or numbers</div>
<input type="text" id="address" name="address" value="${user.address}"/>
<button>Change address</button>
</form>
</div>
When the page is loaded div "row2" is visible and "row2e" is hidden. When I click on "row2" the divs will be changed (using javascript) so that "row2" will be hidden and "row2e" will be visible. At this point Selenium RC can't manage the input in the "row2e" div.
I have the same problem when changing bigger parts of the page using javascript (without submitting the page).
Any ideas why this happens?
Are you making RC wait a moment for the change to happen? In many UI scripting frameworks, the runner won't wait for the interactive results of something you've done unless you tell it to. Normally using iMacros (poor man's Selenium) I only have to wait for automated postbacks, but even JS execution can take longer than a fast computer running Selenium is willing to wait. Have it sleep for half a second before trying to access the newly visible controls.
I recommend using TestPlan for pages that have a lot of changing elements. It has an intelligent waiting system, such that if an element doesn't exist it waits a few moments before continuing. This lets you write tests without having to worry to much about whether the element is static or dynamic.
For a quick example you could here type:
Click //div[@id="row2"]
Click //div[@id="row2e"]//button
If the button is a dynamic element TestPlan will wait a few seconds for it to appear and then click it. But for the most part you just use the page as a user and TestPlan will figure out what to do.
BTW, it can use Selenium as a backend, in addtion to HTMLUnit.
精彩评论