Selenium IDE将其导出为Java / Junit
driver.findElement(By.cssSelector(".x-btn-inner:contains('Yes')")) .click();
并且它不起作用,因为CSS中不存在包含。所以我想通过XPath
driver.findElement(By.xpath("//.x-btn-inner[contains(., 'Yes']")).click();
这段代码不起作用,我做错了什么?
<span id="button-1006-btnEl" data-ref="btnEl" role="presentation" unselectable="on" style="" class="x-btn-button x-btn-button-default-small x-btn-text x-btn-button-center "><span id="button-1006-btnIconEl" data-ref="btnIconEl" role="presentation" unselectable="on" class="x-btn-icon-el x-btn-icon-el-default-small " style=""></span><span id="button-1006-btnInnerEl" data-ref="btnInnerEl" unselectable="on" class="x-btn-inner x-btn-inner-default-small">Yes</span></span>
id是动态生成的,所以我无法使用它。
答案 0 :(得分:1)
您可以通过短信获取:
driver.findElement(By.xpath("//span[. = 'Yes']")).click();