kunal soni
kunal soni

Reputation: 595

selenium webdriver : How to click on particular button having classes applied to each. Unable to find exact x-path

Q. Same kind of class applied to all Download button,How to distinct them from each other? Let's say i want to click on 3rd number of download button. Find a xpath for that button.

I have tried this but it's common for all.

//div[@class='statement-download']

enter image description here

enter image description here

    <div class="statement-download">
       <button class="btn btn-sm btn-icon btn-outline btn-default mb-0" type="button">
       <i class="mdi mdi-download m-r-5"></i>
       <span>Download</span>
       </button>
   </div>

Upvotes: 1

Views: 49

Answers (4)

Zakaria Shahed
Zakaria Shahed

Reputation: 2707

It's a better way you can do it by using loops if you have multiple operations

        List<WebElement> statementdownload = 
       driver.findElements(By.xpath("//div[@class='statement-download']"));

        for (int i=0;i<statementdownload.size();i++) {
            statementdownload.get(i).click();
            statementdownload.get(i).getText();

           // You can use your condition here

             }

Upvotes: 0

Guy
Guy

Reputation: 50909

You can use the date as a starting point

date = 'July 2048'
//div[.='{date}']/following-sibling::div[@class='statement-download']

Upvotes: 0

frianH
frianH

Reputation: 7563

For 3rd, try following xpath:

(//div[@class='statement-download'])[3]

Upvotes: 0

Ed Bangga
Ed Bangga

Reputation: 13016

use the index of the parent div.

//div[@class='statement-card'][3]/div[@class='statement-download']

Upvotes: 1

Related Questions