But when I make t...">

Click button selenium java

I have a button:

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

But when I make the command:

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

The click does not work. 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"); } 
+4
source share
4 answers

type in your case is a button , not a submit .

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

+3
source

You can try this 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(); 
+2
source

You can check if this button is on or not. If so, you need to switch to the frame, and then find and click.

Hope this helps you.

0
source

Just try the code below for click

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

Source: https://habr.com/ru/post/1480496/


All Articles