I'm testing a reasonably complex web application. I can get selenium to get things to the point where a button appears on the screen.

I want selenium to click that button after it appears. But it's not enough to use waitForElementPresent because when the button appears, it is disabled for a split second.

I need selenium to actually wait until the button is clickable before trying to click it.

I'm having no luck even trying to find out if this is possible within the IDE.

Thanks for any assistance!
It's worth re-iterating, right now I am using the IDE only. For now....

有帮助吗?

解决方案 2

I would really recommend you moving over to using webdriver 'proper', automating a complex app via just the IDE is going to cause you to end up in a mess eventually. However that is not your question and I have preached enough...

You have a few options, one might be that you get away with changing from waitForElementPresent to waitForVisible as element present just checks that the element exists on the page.

The next simplest change of that does not work is to hard code a wait into your script, hard coded waits are typically poor practice but you may get away with it if this is just a quick and dirty thing, just use the pause command (remember this takes time in milliseconds not seconds).

The last option is to use the more advanced feature waitForCondition which takes in a piece of javascript to evaluate, with this can you do extra checks on the element in question that can check for any property that identified it as ready to click.

其他提示

I had the same issue with Selenium IDE. I was looking for an equivalent to the ExpectedConditions.elementToBeClickable method in Selenium.

Using Selenium IDE, the following seems to work for testing an form submit input which is disabled using the disabled attribute. YMMV. Adapted as needed.

Add this Selenium IDE command before the click/clickAndWait/submit/submitAndWait command:

    Command: waitForCssCount
    Target: #submit-button[disabled="disabled"]
    Value: 0

This css selector matches an element with id submit-button which has a disabled attribute set to 'disabled'. This command will wait until there 0 occurrences, i.e. the button is no longer disabled.

There is also a waitForXpathCount command available if you prefer to use a Xpath expression rather than a CSS selector.

Note: During testing i've noticed Selenium IDE being a little flaky and doesn't always reliably wait even with this waitForCssCount. YMMV.

I have seen that there is a waitForVisible command. You might want to try it. Waiting for the DOM to load the element (waitForElementPresent) and the loaded element actually becoming visible (waitForVisible) could be two different things.

You could just use waitForElementNotPresent and give the button CSS with the disabled attribute. If the disabled attribute does not exist, the button is active, so there you have your code.

Here is the example that I used for Selenium IDE:

Command | Target | Value waitForElementNotPresent | css= input[disabled=""]|

Your CSS can differ from your code, like having disabled="disabled" as a state, but the principle remains the same.

Using a CSS selector, I was able to use the not pseudo-selector in combination with wait for element visible.

wait for element visible
css=.btn.btn-primary:not([disabled=disabled])
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top