0

Im using selenium basic with vba to automate my code to go to google, sign in, sort by last updated and download file to excel now the issue is that the file's ID keeps on changing, is there a code to add to mine to make it click on the download file i need? even though the ID keeps changing?


    Dim bot As WebDriver
    Set bot = New WebDriver
    Dim i As Integer
    Dim txt As String, link As String
    bot.Start "chrome"
    bot.Get "sharepoint link"
    bot.FindElementById("UserName").SendKeys "user"
     bot.FindElementById("Password").SendKeys "pass"
     bot.FindElementById("btnSubmit").Click
     bot.FindElementById("lastupdated").Click
    bot.FindElementById("lastupdated").Click 
   bot.FindElementById("downloadExcel").Click (i want the download id here for the changing ID)
     
   Stop

End Sub```
nothing
  • 11
  • 3
  • Hey and welcome? Can you share the EXCEL file or the vba code, so we can review it? – KargWare Feb 19 '21 at 17:19
  • yes ofcourse @KargWare – nothing Feb 19 '21 at 17:40
  • `Sub Google_search() Dim bot As WebDriver Set bot = New WebDriver Dim i As Integer Dim txt As String, link As String bot.Start "chrome" bot.Get "sharepoint link" bot.FindElementById("UserName").SendKeys "user" bot.FindElementById("Password").SendKeys "pass" bot.FindElementById("btnSubmit").Click bot.FindElementById("lastupdated").Click bot.FindElementById("lastupdated").Click bot.FindElementById("downloadExcel").Click (i want the download id here for the changing ID) Stop End Sub` @KargWare – nothing Feb 19 '21 at 17:49
  • Does any part of the ID remain constant? Does it position either absolute or relative remain static? Sharing a relevant html section (not as an image) is also important. – QHarr Feb 19 '21 at 19:45
  • @QHarr there is one thing that remains constant something i forgot it but its like this ud-ui-3425 if i inspect it again it would be like this ud-ui-67 – nothing Feb 19 '21 at 20:51
  • `bot.FindElementByCss("[id^='ud-ui-']").click` Though if there are numerous ids on the page that start with that same string you will need to expand the css selector with additional locators to narrow down to one; or index into returned webElements collection (using `bot.FindElementsByCss("[id^='ud-ui-']")(index....).click` ) – QHarr Feb 19 '21 at 21:00
  • @QHarr thank you so much but can you tell me more about this index i never coded css – nothing Feb 19 '21 at 23:37
  • https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors and with `bot.FindElementsByCss("[id^='ud-ui-']")` << that returns a collection. The first would be item 1 (I think) so `bot.FindElementsByCss("[id^='ud-ui-']")(1)` , 2nd item in the collection would `bot.FindElementsByCss("[id^='ud-ui-']")(2)` See also: https://stackoverflow.com/questions/14377590/queryselector-and-queryselectorall-vs-getelementsbyclassname-and-getelementbyid – QHarr Feb 19 '21 at 23:59
  • 1
    @QHarr ill see how it goes and check the links you sent me thank you so much – nothing Feb 20 '21 at 00:15

0 Answers0