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 :)

QHarr
  • 83,427
  • 12
  • 54
  • 101
Wolf Kolev
  • 121
  • 1
  • 1
  • 8
  • Did this get solved? – QHarr Aug 17 '19 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. – ComputerVersteher Aug 17 '19 at 22:40

4 Answers4

1

You can try with xpath :

.FindElementByXPath("//*[@ng-click='download()']").Click
frianH
  • 7,295
  • 6
  • 20
  • 45
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
QHarr
  • 83,427
  • 12
  • 54
  • 101
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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
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
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43