javascript - Selenium(网络驱动程序)- 无法单击拆分按钮的右边缘(请参见图片链接)

标签 javascript selenium css-selectors selenium-webdriver

我需要你的帮助来单击拆分按钮的右边缘(请参阅按钮和 Html 代码的链接)

在屏幕中我们有 2 个按钮,我想点击他右边缘的状态按钮(第二个按钮)。

问题+Html代码:

http://tinypic.com/r/2nbejvp/8

我试过下面的代码(没用)..

选项 1:

SeleniumApi.driver.findElement(By.xpth("//*[@id='ext-gen51']"));
or
SeleniumApi.driver.findElement(By.id("ext-gen51));

选项 2:

 WebElement ele = SeleniumApi.driver.findElement(By.xpath("//*[@id='ext-gen51']"));
 Actions build = new Actions(SeleniumApi.driver);  
 build.moveToElement(ele, (buttonwidth/2)+6, 0).click().build().perform();

选项 3:

 WebElement first = SeleniumApi.driver.findElement(By.id("ext-gen51"));
 first.sendKeys(Keys.PAGE_DOWN);

选项 4:

WebDriverWait wait = new WebDriverWait(SeleniumApi.driver,30);
By findBy = By.cssSelector("tbody.x-btn-icon-small-left td.x-btn-mr");
WebElement element =    wait.until(ExpectedConditions.elementToBeClickable(findBy));
element.click();

WebDriverWait wait = new WebDriverWait(SeleniumApi.driver,30);
By findBy = By.cssSelector("tbody.x-btn-icon-small-left em.x-btn-split");
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(findBy));
element.click();

选项 5:

WebElement ele = SeleniumApi.driver.findElement(By.id("ext-gen51"));
ele.click();
Actions build = new Actions(SeleniumApi.driver);  
build.moveToElement(ele, ele.getSize().getWidth()/2-5, 0).click().perform();

注意事项:

页面是用 extJS 框架生成的

我有 2 个拆分按钮,我想点击第二个。

最佳答案

第一个选项不起作用,findElement(By.id("//*[@id='ext-gen88']")),如您所见//*[@id='ext-gen88'] 是一个 xpath 而不是 id。当提供 id 时,您可能不必担心 xpath 或 cssSelectors,id 是访问任何元素的更好、更简单的方法。

所以下面的代码可以工作,

WebElement element = driver.findElement(By.id("ext-gen88"));
element.click();

或者您可以等待元素出现 explicit wait ,

WebElement element = new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.id("ext-gen88")));
element.click();

关于javascript - Selenium(网络驱动程序)- 无法单击拆分按钮的右边缘(请参见图片链接),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22011713/

相关文章:

javascript - 多个物体不摆动,保持卡住

javascript - 导入有依赖的NPM模块

javascript - 使用 AJAX 调用 Ruby(不是 Rails)变量

html - 如何将 nth-child 与 :hover to style multiple children? 一起使用

javascript - 有没有办法将 ngClass 附加到伪类?

javascript - 如何使用 jquery 获取文件输入中删除文件的值?

python - 如何使用 chromedriver 在 chromium-embedded 中设置用户数据目录?

vba - Excel VBA Selenium 打开本地网页运行时错误以及内存不足错误

java - 在 Selenium 中测试 GWT SimplePager ImageButton 启用状态

jquery - 如何停止 css 属性 font-size 以从外部样式表通用选择器覆盖