Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button click selenium java

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");
}
like image 675
Julien P. Avatar asked May 13 '13 14:05

Julien P.


People also ask

How does Selenium handle button click in Java?

Buttons. The Selenium click button can be accessed using the click() method.

Why button click is not working in Selenium?

We can list the most common reasons for click problems as being one of the following: Wrong web element locations. The existence of a web element that obscures the web element that we want to click. The Selenium WebDriver works much faster than the response of the application.

What is ContextClick () used for?

ContextClick Method. Right-clicks the mouse at the last known mouse coordinates.


2 Answers

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();
like image 80
Omkar Avatar answered Oct 01 '22 14:10

Omkar


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']

like image 43
Ievgen Avatar answered Oct 01 '22 12:10

Ievgen