selenium:找到正确的按钮但无法使用类名单击
selenium: find the right button but fail to click by using className
我尝试通过两种方式找到按钮。第一个直接通过正在工作的 xpath。但是第二种方法不起作用。使用 click() 函数后没有任何反应也没有错误。
第一种方式:
By.xpath(".//*[@id='app:viewAppInsideConfirm:confirmInside:j_id300']").click()
第二种方式:
By.className("iceCmdBtn").click()
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>
顺便说一句:
我尝试使用 xpath 查找不同的项目,我得到:
使用'sumbit'作为关键字可以找到它,但与By.className("iceCmdBtn")相同,但使用click()没有动作...
String xpathLocater = ".//*[@type='submit']";
driver.findElement(By.xpath(xpathLocater)).click();
对于“是”,我在查找元素时出错...
String xpathLocater = ".//*[@value='是']";
driver.findElement(By.xpath(xpathLocater)).click();
伙计们!!!
它还有另一个按钮:
所以我想我需要使用 FindElements
假设 id
的动态部分在您的示例中是 300
,您可以使用 starts-with()
:
应用部分检查
By.xpath(".//input[starts-with(@id, 'app:viewAppInsideConfirm:confirmInside:') and @class='iceCmdBtn']").click()
我尝试通过两种方式找到按钮。第一个直接通过正在工作的 xpath。但是第二种方法不起作用。使用 click() 函数后没有任何反应也没有错误。
第一种方式:
By.xpath(".//*[@id='app:viewAppInsideConfirm:confirmInside:j_id300']").click()
第二种方式:
By.className("iceCmdBtn").click()
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>
顺便说一句:
我尝试使用 xpath 查找不同的项目,我得到:
使用'sumbit'作为关键字可以找到它,但与By.className("iceCmdBtn")相同,但使用click()没有动作...
String xpathLocater = ".//*[@type='submit']";
driver.findElement(By.xpath(xpathLocater)).click();
对于“是”,我在查找元素时出错...
String xpathLocater = ".//*[@value='是']"; driver.findElement(By.xpath(xpathLocater)).click();
伙计们!!!
它还有另一个按钮:
所以我想我需要使用 FindElements
假设 id
的动态部分在您的示例中是 300
,您可以使用 starts-with()
:
By.xpath(".//input[starts-with(@id, 'app:viewAppInsideConfirm:confirmInside:') and @class='iceCmdBtn']").click()