简体   繁体   English

按钮单击selenium java

[英]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");
}

type in your case is button , not submit . type在你的情况是button ,而不是submit

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

You can try this one too as CSS Selector 您也可以像CSS Selector一样尝试这个

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

or 要么

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

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. 希望这会帮助你。

Just try the below code for click 只需尝试以下代码click

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM