I am not able to click on onclick button .Please suggest if you need more clarifications.

155 views
Skip to first unread message

Srinivas Vedula

unread,
Dec 9, 2015, 6:53:05 AM12/9/15
to Selenium Users
<h2 id="expertContent" class="expander" collapsed="true">
<button onclick="toggle('expertContent');">I Understand the Risks</button>
</h2>

Zahi Zilberman

unread,
Dec 9, 2015, 9:30:47 AM12/9/15
to Selenium Users
Add a snippet of your code...

Anand S.

unread,
Dec 9, 2015, 12:22:21 PM12/9/15
to Selenium Users
Issue is with Single quote in toggle('expertContent') onclick value.

Solution 1 : //h2[@id='expertContent']/button[contains(text(),'I Understand the Risks')]

Srinivas Vedula

unread,
Dec 10, 2015, 4:04:23 AM12/10/15
to Selenium Users
I have a requirement when user suppose enter this page "https://cacert.org/" , it will ask for SSL certificate , then i will click on "I Understand the Risk" link then click on "Add Exception" Button then it will open "Add Security Exception" pop up then click on "Confirm security Exception" button. I don't want to over ride SSL certificate error

Refer my code snipet::

public class main_script {

public static WebDriver driver;
@Test
public void test() throws Exception{
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("work");
myprofile.setAcceptUntrustedCertificates(false);
WebDriver driver = new FirefoxDriver(myprofile);
        driver.manage().window().maximize();
     
        driver.get("https://cacert.org/");
        
       driver.findElement(By.id("expertContent")).click();
      
       
       driver.findElement(By.id("exceptionDialogButton")).click();
 
        
   
}
So  i am not able to click on "I Understand the Risks" link

Siva Kumar

unread,
Dec 10, 2015, 4:14:51 AM12/10/15
to Selenium Users
driver.findElement(By.Xpath(//h2[@class='expander' and contains (text() ,'I Understand the Risks')])) ;

Zahi Zilberman

unread,
Dec 10, 2015, 4:25:22 AM12/10/15
to Selenium Users
I think your element selection is wrong, you should select the button not the h2


On Wednesday, December 9, 2015 at 1:53:05 PM UTC+2, Srinivas Vedula wrote:

Srinivas Vedula

unread,
Dec 10, 2015, 8:24:07 AM12/10/15
to Selenium Users
It shows error -
Unable to locate element: {"method":"xpath","selector":"//button[@class='expander' and contains (text() ,'I Understand the Risks')]"}
Command duration or timeout: 46 milliseconds

Krishnan Mahadevan

unread,
Dec 10, 2015, 8:30:28 AM12/10/15
to Selenium Users
See if this works :

WebElement button = driver.findElement(By.xPath("//h2[@class='expander']/button"));
String content = (String) driver.executeScript("return arguments[0].innerHTML;",button);

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b21cde53-0f5f-4fc4-b161-36928c409ac5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

PeterJeffreyGale .

unread,
Dec 10, 2015, 8:32:31 AM12/10/15
to seleniu...@googlegroups.com

Expander is not the class attribute of your target element

--

Srinivas Vedula

unread,
Dec 10, 2015, 8:58:39 AM12/10/15
to Selenium Users
 
This  code 
driver.findElement(By.id("expertContent")).click();
 is able to highlight the "'I Understand the Risks" element but it is not getting  expanded when it will expand then i am able to click 'Add Exception" button.

      
       So this code fails
       driver.findElement(By.id("exceptionDialogButton")).click();

so my script fails with exception - Timed out after 10 seconds waiting for visibility of element located by By.id: exceptionDialogButton

An the above given solutions did't worked.

PeterJeffreyGale

unread,
Dec 10, 2015, 9:27:12 AM12/10/15
to Selenium Users
So, perhaps you need to click on the h2 tag to expand the section, and then click on the button?

Srinivas Vedula

unread,
Dec 10, 2015, 12:40:07 PM12/10/15
to Selenium Users
Yes exactly i want to click on the h2 tag to expand the section, and then click on the button.

PeterJeffreyGale .

unread,
Dec 10, 2015, 2:59:13 PM12/10/15
to seleniu...@googlegroups.com

So what's the problem with doing that?

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/wZZnMh1qy3E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Srinivas Vedula

unread,
Dec 11, 2015, 12:37:16 AM12/11/15
to Selenium Users
When i click the h2 tag it is not getting expanded, so i am not able to click the below button

PeterJeffreyGale

unread,
Dec 11, 2015, 4:30:55 AM12/11/15
to Selenium Users
From your sample html, we can see a javascript event that will get triggered when you click on the <a> element, but there is nothing we can see on the <h2> that might cause anything to happen when you click on it.

So maybe it's not actually the <h2> element that you need to click on as your fist step. You need to look to see which actual element will cause that to happen, though it might not be easy to tell, you might need to talk to the developers to work it out, though obviously, in this case they will not be available to you.

The site you are mentioning requires us to sign up before we can get to the actual page that are working with, and I for one am not willing to do that.

Why do you need to build an automation script for this particular site? It either seems a little suspicious in terms of what you are trying to achieve, or if you can describe your high level requirement for working with it, someone might be able to suggest a better way of achieving your goal.

Srinivas Vedula

unread,
Dec 14, 2015, 1:56:30 AM12/14/15
to Selenium Users
Hi Peter ,
Thanks for your concern now he have decided to bypass this SSL certificate and not to handle the click events.
We can close this thread.
Reply all
Reply to author
Forward
0 new messages