0

There are two buttons on application named as "download" & "upload" with same properties/identifiers. Can someone help me how to click on button & how to handle such objects. I have tried CSS Selector, XPath other combinations as well, nothing worked for me. looking for Java code. below is the HTML for those buttons:

<div class="control-label col-md-6 control-label-left"> <button class="btn blue form-control-btn" ngf-select="vm.uploadDemographic($file)"> <i class="fa fa-upload"/> Upload Template </button> </div> 2nd Button <div class="control-label col-md-6 control-label-left"> <button class="btn blue form-control-btn" ng-click="vm.downloadTemplate('demographic')"> <i class="fa fa-download"/> Download Template </button> </div>
2
  • 1
    Welcome to Stack Overflow! Please review How to ask questions on Stack Overflow and what types of questions can be asked and what types should be avoided Commented Nov 13, 2017 at 9:09
  • The CSS for both the WebElement is identical so in absence of id or name attribute to construct an unique css_selector or an xpath we need to see some portion of the outerHTML. Commented Nov 13, 2017 at 10:28

2 Answers 2

1

Try to use the following CSS Selector: .btn.blue.form-control-btn. It must help you.

Code:

buttons = driver.findElements(By.cssSelector(".btn.blue.form-control-btn"));
buttons.get(0).click(); // Click on the first button.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for quick response, i tried that before it's not working as both the buttons have same class. please check above html once. 1st & 2nd button HTML code & also unable to click by index.
0

Try this for finding your buttons:

For download button: driver.findElement(By.xpath("//*[text()='Download Template']"));

For upload button: driver.findElement(By.xpath("//*[text()='Upload Template']"));

Comments

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.