Forum

Selenium Vba: Click...
 
Notifications
Clear all

Selenium Vba: Click button on web page

6 Posts
2 Users
0 Reactions
739 Views
(@raj)
Posts: 21
Eminent Member
Topic starter
 

Hi Team, Im trying to click on the below button but i couldn't, below is the html code i have.

I tried with xpath like

  driver.FindElementByXPath("//a[contains(text(),'https']").Click

  driver.FindElementByXPath("//a[@href,'#']").Click   ' this work, but this clicks on sign out drop down button

  driver.FindElementByXPath("//a[@class,'btn btn-default']").Click

Could some one help me in this. Thanks

<a href="#" class="btn btn-default" data-bind="click : downloadFiles, visible: $root.attachmentsViewModel.files().length > 0">
<i class="fa fa-download js-app-action-el" aria-hidden="true"></i>
Download <strong data-bind="text:$root.attachmentsViewModel.files().length">5</strong> Files
</a>

 
Posted : 28/07/2020 7:29 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi,

It'll be easier to do if you can supply the url of the page rather than just having a fragment of the age to work with.

regards

Phil

 
Posted : 28/07/2020 8:50 am
(@raj)
Posts: 21
Eminent Member
Topic starter
 

Hi Philip, thanks for the immediate reply.. I don't have rights to send the URL details.. that is the reason I have not included URL in the post. When I checked, I for the above html code for that particular button... Is it possible to guide with that code .. Thanks

 
Posted : 28/07/2020 10:32 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Rajsha,

If it's not publicly accessible or requires a login, can you at least view the page source code and copy/paste that into a text file.

There are some techniques of locating elements that require the entire page to be known, for example, locating the nth <a> tag.  Without knowing how many <a> tags, or buttons, are on the page, I can't properly use that approach.

Phil

 
Posted : 28/07/2020 10:48 pm
(@raj)
Posts: 21
Eminent Member
Topic starter
 

Hi Philip,

I found the solution for the button, below is the code that i have found to click on the button.

.FindElementByXPath("//a[@class='btn btn-default'][1]").Click

Since in the 4th post you stated (locating the nth <a> tag.) this gave me the clue to find the above code. There are 5 buttons total i the web page and the button i need is located the 2nd place of a> tag.

Thank you Philip for the idea.

Thanks

Rajsha

 
Posted : 29/07/2020 8:48 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

No worries.  That's why I needed the whole page so I could count things like that 🙂

 
Posted : 29/07/2020 8:55 am
Share: