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
  • 80,579
  • 10
  • 51
  • 94
Wolf Kolev
  • 91
  • 1
  • 1
  • 7
  • 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
  • 6,710
  • 6
  • 17
  • 42
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
  • 80,579
  • 10
  • 51
  • 94
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
  • 151,581
  • 34
  • 225
  • 281
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,649
  • 11
  • 33
  • 43