按钮单击SeleniumJava

按钮单击SeleniumJava,java,selenium,webdriver,selenium-webdriver,Java,Selenium,Webdriver,Selenium Webdriver,我有一个按钮: <input type="button" onclick="onOpenSessionClick()" value="Open device access"> 单击不起作用。 这是我的密码: if (isElementPresent((By.xpath("//input[@value='Open device access']")))) { System.out.println("Je suis dans le if"); Thread.

我有一个按钮:

<input type="button" onclick="onOpenSessionClick()" value="Open device access">     
单击不起作用。 这是我的密码:

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

类型
在您的案例中是
按钮
,而不是
提交

试试这个
//输入[@value='Open device access']

//输入[@value='Open device access'和@type='button']

您也可以作为CSS选择器尝试使用此选项

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


只需为
点击

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

您可以检查此按钮是否在框架上。如果是,则需要切换到帧,然后找到并单击


希望这能对您有所帮助。

谢谢,我的问题不在于单击,而在于按钮是否在javascript手风琴中。但是元素不可见,所以我认为javascript没有被执行。一个解决方案?我不完全理解一个问题,你能提供更多的细节吗?谢谢,我的问题不是点击,而是按钮在javascript手风琴中。但是元素不可见,所以我认为javascript没有被执行。一个解决方案?你能研究一下吗?我想这可能会解决你的问题。但没有完全确定。谢谢,但我认为我的webdriver seveur不执行javascript。我所有的脚本都在本地运行。我的服务器在Debian 1.6.0上,IceweaselOP使用的是Webdriver绑定,而不是原来的Selenium。我也有同样的问题,有解决方案吗?在我的例子中,浏览器启动了,A..B..C然后当它到达点击该按钮的点时,浏览器关闭。好的注释对其他人有帮助
driver.findElement(By.cssSelector("input[type='button']")).click();
selenium.focus("name=Valuation"); //name of button
selenium.click("Valuation"); //pass that name to click