Clicking of a button which is disabled by default using webdriver

743 views
Skip to first unread message

Aquasush

unread,
Jan 27, 2014, 4:31:36 PM1/27/14
to webd...@googlegroups.com
Hi Webdriver team,
Im working on UI automation using Webdriver.
I have a Next button that is disabled by default.
<button id="pt1:r1:0:pt1:cb2" class="btn-primary af_commandButton p_AFDisabled p_AFTextOnly" disabled="">Next</button>
 
After a checkbox is clicked the ,the button attribute disabled is removed and the button can be clicked when done manually. I m unable to achieve this using webdriver.
The checkbox is clicked ,even if I use Thread.sleep or explicit wait for a condition to occur also the button is still in disabled state so the button click is not happening.
The HTML of button element once checkbox is clicked is as follows:
<button id="pt1:r1:0:pt1:cb2" class="btn-primary af_commandButton p_AFTextOnly" onclick="return false;">Next</button>
 
PLease help me as am stuck at this point to move further.
 
Im using FF 26.0,windows 8,Selenium 2.39 version.
 
Regards,
Aquasush

Ved Prakash

unread,
Jan 30, 2014, 1:05:39 AM1/30/14
to webd...@googlegroups.com
I think you can do this by using JavaScript executor interface and not through WebDriver.

Something like 

(JavascriptExecutor(webdriver)).executeScript("document.getElementsById('PutYourButtonIdHere').click();");

Hope that helps!

darrell

unread,
Jan 30, 2014, 8:00:14 AM1/30/14
to webd...@googlegroups.com
Not enough information. The most obvious answer is whatever you think is happening manually is wrong. You have automated what you think happens during manual testing but you have not actually automated the right thing. You need to understand what ACTUALLY happens when you click the checkbox and automate what is ACTUALLY happening.

Ram Prasad

unread,
Jan 30, 2014, 8:03:52 AM1/30/14
to webd...@googlegroups.com
you can do it via javascriptexuecutor you find the webelement and do getText() on it by executing javascript


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

darrell

unread,
Jan 30, 2014, 10:22:59 AM1/30/14
to webd...@googlegroups.com
This is not always a good option. I recently worked on a project where clicking a button was failing. So someone changed the code to use JavascriptExecutor to click the button. It made the test go green and development continued. A few weeks later they added more features to the page. This caused the button to move off the screen and because of the library they were using, the button could not be scrolled onto the screen. The JavascriptExecutor click continued to work and the test stayed green. Unfortunately, it was impossible to click the button with a mouse. So if we had not caught this mistake, we could have shipped the application with a button the user could not click.

The whole point of test automation is to re-run tests over and over again in the hopes it will catch us breaking old requirements when we add new features. Using a JavascriptExecutor to make the test go green is great if all you want to do is make all your tests green. There is a reason Selenium will not let you click on invisible elements. You want to simulate end user interactions. If you end users are not writing GreaseMonkey scripts then you should not be using JavascriptExecutor.

Darrell

Ram Prasad

unread,
Jan 30, 2014, 10:02:11 PM1/30/14
to webd...@googlegroups.com
I agree with the fact the webdriver emulates user actions more closely by using native events, however as the question was asked on webdriver and we assume the author of the question is better judge over how he wants to test the app.lets close the thread here and Aquasush  can comment if he has anything to say

darrell

unread,
Jan 31, 2014, 9:49:03 AM1/31/14
to webd...@googlegroups.com
Ram,

Your response comes across as "shut up". If you are a moderator of this group and want me to shut up I will. If you are not a moderator of this group then why are you saying "lets close the thread here"? My intent was to make sure everyone understood a situation using JavascriptExecutor had negative results for me. I believe I did that; I had no intention of following up on this.

You indicate "we ASSUME the author of the question is a better judge over how he wants to test the app." I thought it important to not ASSUME Aquasush OR ANYONE ELSE READING THIS THREAD understood the dangers of using JavascriptExecutor. Now that Aquasush and everyone reading this thread understands the dangers of using JavascriptExecutor I trust they can make an INFORMED decision. If Aquasush decides to use JavascriptExecutor for whatever reason then that is fine because I'm comfortable with fact they are making an informed decision. However, I have seen very smart people ASSUME it was safe to use and find their tests giving them a false positive.

Bottom line, your response to my message feels like you are taking offense and telling me to shut up. If this is true I'm sorry you are taking that way. However if you re-read my message you will see that I DID NOT say it was ALWAYS a bad idea. I was just informing everyone that I have seen SOME situations were it can lead to a false positive. My intent was to inform people of the POTENTIAL danger of JavascriptExecutor. 

Ram Prasad

unread,
Feb 1, 2014, 11:55:22 PM2/1/14
to webd...@googlegroups.com
Dareell

Dont read too much into it, I only expected Aquasush  to make things clear as he has not responded yet, his real problem , what he wants to do etc,
dont take it personal buddy cheers,

susanth.nair

unread,
Feb 2, 2014, 2:18:44 AM2/2/14
to webd...@googlegroups.com
Darell

I have a point to say on top of this
I gave a solution to the problem here - the solution was an Xpath
Then you stated on top of that by saying Xpath is not a rte solution so please use this CSS ( but it was the same solution in the form of css)

As per my experience in some of the selenium automation situation we can not say that this is the only approach
That should be decided based on the application nature and the how the event handled in application by the UI developer using java script libraries

I do think that selenium can give a single solution for all kind of application behavior

So what i feel is , it is not a mistake to use JavascriptExecutor to handle the situation ( also selenium providing By.xpath also if it is really not a good approach to use dnt let the user to , it can be deprecated)
 

susanth.nair

unread,
Feb 2, 2014, 2:39:56 AM2/2/14
to webd...@googlegroups.com
Darell

I have a point to say on top of this
I gave a solution to the problem here - the solution was an Xpath
Then you stated on top of that by saying Xpath is not a rte solution so please use this CSS ( but it was the same solution in the form of css)

As per my experience in some of the selenium automation situation we can not say that this is the only approach
That should be decided based on the application nature and the how the event handled in application by the UI developer using java script libraries

I do think that selenium can give a single solution for all kind of application behavior

So what i feel is , it is not a mistake to use JavascriptExecutor to handle the situation ( also selenium providing By.xpath also if it is really not a good approach to use dnt let the user to , it can be deprecated)


2014-02-02 <postm...@bergmeister-kunstschmiede.de>:
Dies ist eine automatisch erstellte Benachrichtigung über den Zustellstatus.

Übermittlung an folgende Empfänger fehlgeschlagen.

       s.kr...@bergmeister-kunstschmiede.de




Final-Recipient: rfc822;s.kr...@bergmeister-kunstschmiede.de
Action: failed
Status: 5.1.1
Reply all
Reply to author
Forward
0 new messages