-1

I can't clic a button in Selenium Webdriver using Excel VBA. I have tried with FindElementByXPath, byID, and seems like it does not find the element. I have searched for any iframe in the code but did not find any.

Here is the code:

code

It calls this function: enter image description here

Thanks in advance!!!

Rebeca B.
  • 19
  • 6

2 Answers2

0

To click() on the element you can use either of the following Locator Strategies:

  • Using FindElementById:

    bot.FindElementById("btaltaP").Click
    
  • Using FindElementByCss:

    bot.FindElementByCss("a#btaltaP[name='btalta'][title='Nuevo presupuesto']").Click
    
  • Using FindElementByXPath:

    bot.FindElementByXPath("//a[@id='btaltaP' and @name='btalta'][@title='Nuevo presupuesto']").Click
    

Update

As it is a <form> element you can also try with Submit as follows:

  • Using FindElementById:

    bot.FindElementById("btaltaP").Submit
    
  • Using FindElementByCss:

    bot.FindElementByCss("a#btaltaP[name='btalta'][title='Nuevo presupuesto']").Submit
    
  • Using FindElementByXPath:

    bot.FindElementByXPath("//a[@id='btaltaP' and @name='btalta'][@title='Nuevo presupuesto']").Submit
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for your help but it is not working. That code does not find the element... – Rebeca B. Feb 09 '21 at 11:42
  • @RebecaB. The element is possibly within an _`overlay`_ you need to add some waits. – undetected Selenium Feb 09 '21 at 11:44
  • I have added a 10 seconds wait but it is still crashing. I do not know how to handle errors in this case but I think that for some reason it is not finding the button. – Rebeca B. Feb 09 '21 at 12:02
  • @RebecaB. Can you crosscheck if the element is within an [iFrame](https://stackoverflow.com/questions/53203417/ways-to-deal-with-document-under-iframe/53276478#53276478)? – undetected Selenium Feb 09 '21 at 12:05
  • I've looked it up in the code and I see nothing. I'm going to put a bigger piece of code in the question right now, to see if you can help me with that. Thank you very much. – Rebeca B. Feb 09 '21 at 14:33
  • Checkout the updated answer and let me know the status. – undetected Selenium Feb 09 '21 at 14:52
  • I have tried with the updated answer but it is not working. When it reaches that instruction it does not generate an error and goes to the next one. However, it does not open the screen that opens when you press the button. Can I call the function instead of pressing the button with Selenium? (I am posting the functions code in the question) – Rebeca B. Feb 09 '21 at 15:40
  • Can you share the URL? – YasserKhalil Feb 09 '21 at 16:20
  • @YasserKhalil Sorry but I can not. I can post a picture of how it shows the button if it helps... – Rebeca B. Feb 09 '21 at 16:26
  • I have tried the IsDisplayed attribute and it returns FALSE. IsEnabled and isPresent both return TRUE. – Rebeca B. Feb 09 '21 at 16:34
0

Just solved it using ClickDouble, so my code is:

bot.FindElementByXPath("//a[@id='btaltaP' and @name='btalta'][@title='Nuevo presupuesto']").ClickDouble

Thanks a lot!

Rebeca B.
  • 19
  • 6