0

I have table in website. Table allows to select multiple rows by pressing Shift key + Down arrow keys.

I am trying to perform same using selenium webdriver but it's not selecting rows one by one, it select row then unselect it and goes to next....

My Code :

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();

    }
1
  • can u share ur website link? Commented Mar 21, 2016 at 8:48

2 Answers 2

1

You pressing keyDown and keyUp. Try

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();

By the way, perform() is doing build(), no need to call them both.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your input. It is selecting 2 rows in sequence then deselect those 2 rows and select new 2 rows. I have 10 rows and I would like to select all rows in sequence.
1

I believe this should be:

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();

If you have public URL to replicate this then We could try it more easily.

1 Comment

Hi, Thanks for your help as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.