Home > Software design >  Click button by using Selenium
Click button by using Selenium

Time:08-03

I am trying use selenium VBA to download file. However, it cannot work by using FindElementsByXPath(). Below codes were tried, but failed:

driver.FindElementByLinkText(" Download all").Click
driver.FindElementsByXPath ("//span[contains(text(),'Download all')]")
driver.FindElementsByXPath("//span[@class='mat-button-wrapper']//span[contains(text(),'Download all')]").Click
driver.FindElementsByXPath("//button[@mat-raised-button='mat-focus-indicator mat-raised-button mat-button-base mat-primary']").Click
driver.FindElementsByXPath("//button[@class='mat-focus-indicator mat-raised-button mat-button-base mat-primary' and text()='Download all']").Click

Snapshot of the HTML:

enter image description here

CodePudding user response:

To click on the element Download all you can use either of the following locator strategies:

  • Using FindElementByCss:

    driver.FindElementByCss("button.mat-focus-indicator.mat-raised-button.mat-button-base.mat-primary span.mat-button-wrapper").Click
    
  • Using FindElementByXPath:

    driver.FindElementByXPath("//button[@class='mat-focus-indicator mat-raised-button mat-button-base mat-primary']//span[@class='mat-button-wrapper' and text()='Download all']").Click
    
  • Related