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");
}
Buttons. The Selenium click button can be accessed using the click() method.
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.
ContextClick Method. Right-clicks the mouse at the last known mouse coordinates.
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();
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With