简体   繁体   English

硒:找到正确的按钮,但无法使用className单击

[英]selenium: find the right button but fail to click by using className

I try to find the button by using two way. 我尝试通过两种方式找到按钮。 The first by the xpath directly which is working. 第一个由xpath直接起作用。 But the second way is not working. 但是第二种方法不起作用。 after using the click() function nothing happen and no error. 使用click()函数后,没有任何反应,也没有错误。

First way: 第一种方式:

By.xpath(".//*[@id='app:viewAppInsideConfirm:confirmInside:j_id300']").click()

Second way: 第二种方式:

By.className("iceCmdBtn").click()

html: 的HTML:

<input id="app:viewAppInsideConfirm:confirmInside:j_id300" class="iceCmdBtn" type="submit" value=" Yes " onfocus="setFocus(this.id);" onclick="parent.JSsessionTimeOut.resetSessionTimeout();iceSubmit(form,this,event);return false;" onblur="setFocus('');" name="app:viewAppInsideConfirm:confirmInside:j_id300"></input>

BTW: 顺便说一句:

I try to use xpath to find different items, I got: 我尝试使用xpath查找不同的项目,我得到了:

Use 'sumbit' as key word can find it, but same as the By.className("iceCmdBtn") Find but with click() no action... 使用“ sumbit”作为关键字可以找到它,但是与By.className(“ iceCmdBtn”)Find相同,但是使用click()则没有任何操作...

  String xpathLocater = ".//*[@type='submit']"; 
  driver.findElement(By.xpath(xpathLocater)).click();

For the ' Yes ' , I got error to find the element... 对于'是',我找不到元素...

String xpathLocater = ".//*[@value=' Yes ']"; 字符串xpathLocater =“ .//*[@value='是']”; driver.findElement(By.xpath(xpathLocater)).click(); driver.findElement(By.xpath(xpathLocater))。click();

Guys!!! 伙计们!

It have another button: 它有另一个按钮:

So I guess I need use FindElements 所以我想我需要使用FindElements

假设示例中id的动态部分为300 ,则可以使用starts-with()进行部分检查:

By.xpath(".//input[starts-with(@id, 'app:viewAppInsideConfirm:confirmInside:') and @class='iceCmdBtn']").click()

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

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