【问题标题】:Getting issue while trying to select rows in sequence via Selenium Webdriver尝试通过 Selenium Webdriver 按顺序选择行时出现问题
【发布时间】:2016-03-21 17:35:43
【问题描述】:

我在网站上有表。表格允许通过按 Shift 键 + 向下箭头键选择多行。

我正在尝试使用 selenium webdriver 执行相同的操作,但它没有逐一选择行,它选择行然后取消选择它并转到下一个....

我的代码:

List<WebElement> TRcount = driver.findElements(By.tagName("tr"));
    int x;
    for(x=0;x<TRcount.size();x++)
    {

        Actions rows = new Actions(Base.getdriver());

        rows.keyDown(TRcount.get(x),Keys.SHIFT).keyUp(TRcount.get(x+1), Keys.SHIFT).build(); 
        rows.build().perform();
        TRcount.get(x).click();

    }

【问题讨论】:

  • 你能分享你的网站链接吗?

标签: java selenium-webdriver


【解决方案1】:

您按keyDownkeyUp。试试

Actions rows = new Actions(Base.getdriver());
rows.keyDown(Keys.SHIFT).perform();
for(x = 0 ; x < TRcount.size() ; x++)
{
    TRcount.get(x).click();
}

rows.keyUp(Keys.SHIFT).perform();

顺便说一句,perform() 正在做build(),不需要两个都调用。

【讨论】:

  • 感谢您的意见。它依次选择 2 行,然后取消选择这 2 行并选择新的 2 行。我有 10 行,我想依次选择所有行。
【解决方案2】:

我认为应该是这样的:

List<WebElement> TRcount = driver.findElements(By.tagName("tr"));
int x;
Actions rows = new Actions(Base.getdriver());
rows = rows.keyDown(Keys.SHIFT).build(); 
for(x=0;x<TRcount.size();x++)
{
    rows = rows.sendKeys(TRcount.get(x),Keys.DOWN).build(); 
}
rows = rows.keyUp(Keys.SHIFT).build(); 
rows.build().perform();

如果您有公共 URL 来复制它,那么我们可以更轻松地尝试它。

【讨论】:

  • 您好,也感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-04
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
相关资源
最近更新 更多