7

I have a button:

<input type="button" onclick="onOpenSessionClick()" value="Open device access">     

But when I do the command:

driver.findElement(By.xpath("//input[@value='Open access device' and @type='submit']")).click();

The click does not. Here is my code:

if (isElementPresent((By.xpath("//input[@value='Open device access']")))) 
{
    System.out.println("Je suis dans le if");
    Thread.sleep(2000);
    driver.findElement(By.xpath("//input[@value='Open device access' and @type='submit']")).click();
    System.out.println("Je suis dans le if et jai open");
    Thread.sleep(5000);
    assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div/p/span")));                       
    assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input")));                     
    assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input[2]")));                      
    System.out.println("Je suis dans le if et je cherche");
}
1
  • I am also having the same problem, any solution? For my case ,the browser is fired up,does A..B..C then when it reaches the point to click that button, the browser closes up. Commented Aug 13, 2016 at 9:08

4 Answers 4

5

You can try this one too as CSS Selector

driver.findElement(By.cssSelector("input[type='button'][value='Open device access']")).click();

or

driver.findElement(By.cssSelector("input[type='button']")).click();
Sign up to request clarification or add additional context in comments.

3 Comments

thank you My problem is not with the click but finally that the button is in a javascript accordion. But the element is not visible so I think the javascript is not executed. A solution?
Can u look into this link.I think may be this will resolve u r problem.But no fully sure on this.
Thanks but I think of my webdriver seveur does not execute the javascript. Locally all my script works. My server is on a Debian 1.6.0 and Iceweasel
3

type in your case is button, not submit.

Try this one //input[@value='Open device access'] or //input[@value='Open device access' and @type='button']

2 Comments

Thank you My problem is not with the click but finally that the button is in a javascript accordion. But the element is not visible so I think the javascript is not executed. A solution?
I do not understand a question totally, could you please provide more details?
0

You can check whether this button is on frame or not. If it is, then you need to switch to the frame and then locate and click.

Hope this will help you.

1 Comment

Good Note Helpful to others
-2

Just try the below code for click

selenium.focus("name=Valuation"); //name of button
selenium.click("Valuation"); //pass that name to click

1 Comment

OP is using Webdriver bindings not the original Selenium.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.