Jul*_* P. 6 java selenium webdriver selenium-webdriver
我有一个按钮:
<input type="button" onclick="onOpenSessionClick()" value="Open device access">
Run Code Online (Sandbox Code Playgroud)
但是当我执行命令时:
driver.findElement(By.xpath("//input[@value='Open access device' and @type='submit']")).click();
Run Code Online (Sandbox Code Playgroud)
点击不会.这是我的代码:
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");
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你也可以尝试这个 CSS 选择器
driver.findElement(By.cssSelector("input[type='button'][value='Open device access']")).click();
Run Code Online (Sandbox Code Playgroud)
或者
driver.findElement(By.cssSelector("input[type='button']")).click();
Run Code Online (Sandbox Code Playgroud)
type就你而言button,不是submit。
试试这个//input[@value='Open device access']或者
//input[@value='Open device access' and @type='button']
| 归档时间: |
|
| 查看次数: |
57058 次 |
| 最近记录: |