3

I am using Selenium and I would like to be able to click on the following

<a ng-click="download()">download</a>'

This is an 'a' tag. I am not sure how the code would be like to click onto an 'a' tag that has got ng-click in it.

  Dim d As WebDriver
  Set d = New ChromeDriver
Const URL = "url of the website - not public"
With d
    .Start "Chrome"
    .get URL
    .Window.Maximize
    .FindElementById("Search").SendKeys "information to search"
    .Wait 1000
    .FindElementById("Submit").Click
    .Wait 1000
    'then I need to click the following <a ng-click="download()">download</a>
End With

Only step I am missing is to be able to click on that last bit. Thank you for the help in advance :)

2
  • Did this get solved? Commented Aug 17, 2019 at 22:19
  • Intranet Website? Click on Submit suggest a form. If it is a form, check request sended after clicking submit and rebuild that request witj differnt seach phrase. That would be far cleaner and easier thaz bothering with javasxript. Commented Aug 17, 2019 at 22:40

4 Answers 4

1

The desired element is an Angular element you need to induce WebDriverWait for the elementToBeClickable and you can use either of the following Locator Strategies:

  • Using FindElementByCss:

    d.FindElementByCss("a[ng-click^='download']").click
    
  • Using FindElementByXPath:

    d.FindElementByXPath("//a[starts-with(@ng-click, 'download') and text()='download']").click
    
Sign up to request clarification or add additional context in comments.

Comments

1

You can try with xpath :

.FindElementByXPath("//*[@ng-click='download()']").Click

Comments

1

This is what attribute = value css selectors are for. You can target the ng-click attribute by its value:

d.FindElementByCss("[ng-click='download()']").click

Comments

0

It would be easier (and more efficient) to see more relevant HTML code, but you can loop through the a tags and find the one that has the text: download. Once found, you can try to click on it then exit the loop.

Dim a As Selenium.WebElement
For Each a In d.FindElementsByTag("a")
    If a.Text = "download" Then
        a.Click
        Exit For
    End If
Next

1 Comment

Thank you , I will give it a try :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.