java - 按钮单击 Selenium java

标签 java selenium webdriver selenium-webdriver

我有一个按钮:

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

但是当我执行命令时:

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

点击没有。 这是我的代码:

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

最佳答案

你也可以试试这个作为 CSS 选择器

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

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

关于java - 按钮单击 Selenium java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16524290/

相关文章:

python - PhantomJS 网络驱动程序错误代码 -6

c# - Webdriver 等到 Ajax 加载器完成加载

linux - Selenium 2 webdriver - 连接到 http ://localhost:7055 refused

java - 在 Webdriver selenium 上激活 javascript

java - Android Studio : Too much indendation in code formatting

java - 结合使用底部布局和MotionLayout的最佳方法是什么

Selenium 2 : How to save a HTML page including all referenced resources (css, js,图像...)?

javascript - JavaScriptExecutor 中引用 selenium 元素

java - "file:///storage/emulated/0/screenshot.png exposed beyond app through ClipData.Item.getUri()"

java - 在另一个 Observable 中订阅一个 Observable