加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

按钮单击selenium java

发布时间:2020-12-14 19:36:13 所属栏目:Java 来源:网络整理
导读:我有一个按钮: input type="button" onclick="onOpenSessionClick()" value="Open device access" 但是当我执行命令时: driver.findElement(By.xpath("//input[@value='Open access device' and @type='submit']")).click(); 点击不会. 这是我的代码: if
我有一个按钮:
<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");
}

解决方法

在你的情况下输入是按钮,而不是提交.

试试这个//输入[@ value =’打开设备访问’]或//输入[@ value =’打开设备访问’和@type =’按钮’]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读