0

I'm wasting much time,come here to get help on Selenium.

5 lines VBA Code's Goal: click submit button after I put input data. *submit is in Korean.
Goal: Click submit button.
URL: https://datacentersupport.lenovo.com/us/ko/warrantylookup#/
input data: j30a7xlg (this hardcoded in this vba)

Error Des: at line of chd.FindElementByCss with runtime error
Run-time error '11':
ElementNotVisibleError
element not interactable

'--------------------Below is compete Source Code
Sub Scrape()
    Dim chd As New Selenium.ChromeDriver
    chd.Get "https://datacentersupport.lenovo.com/us/ko/warrantylookup#/"
    chd.FindElementByClass("button-placeholder__input").SendKeys "j30a7xlg"

'Below line - ERROR Runtime 
    chd.FindElementByCss("#app-standalone-warrantylookup > div > div.warranty-lookup__content > div > div > div.basic-search__content > button").Click

    chd.Wait 5000
    Stop
End Sub

2 Answers 2

1

Here's a revised version of the code that can help you click the submit button using Selenium in VBA:

Sub Scrape()
    Dim chd As New Selenium.ChromeDriver
    chd.Get "https://datacentersupport.lenovo.com/us/ko/warrantylookup#/"
    
    chd.FindElementByClass("button-placeholder__input").SendKeys "j30a7xlg"
    
    ' Wait for the submit button to become clickable
    chd.WaitElementPresentByCss("#app-standalone-warrantylookup button", timeout:=5000)
    
    ' Click the submit button
    chd.FindElementByCss("#app-standalone-warrantylookup button").Click
    
    chd.Wait 5000
    Stop
End Sub

In this updated code:

1 After entering the input data, we use the WaitElementPresentByCss method to wait for the submit button to become clickable before proceeding. This method waits for a specific element to be present and visible on the page within the specified timeout period.

2 Once the submit button is clickable, we use FindElementByCss to locate and click the button.

3 The subsequent code waits for 5000 milliseconds (5 seconds) before continuing further.

By waiting for the element to become clickable, you can avoid the "ElementNotVisibleError" and ensure the successful click on the submit button.

0

Solved. Thanks to AmMilinPatel's great help. to me it's great!!

Using the help,I(user56534)completed my final source code and share for others's reference.
But it have a bug that I don't know the reason.If anyone know,please generous to me.
[URL-1!]
https://datacentersupport.lenovo.com/ch/ko/warrantylookup#/
[URL-2!]
https://datacentersupport.lenovo.com/ch/ko/products/servers/thinksystem/sr650/7x06/7x06cto1ww/j30a7xlg/warranty
Bug description:The VBA clicks URL-1, then get URL-2 automatically well most case.
But in a great while,between URL-1 and URL-2, a alert window(see attached image) pop up.
In that cast, I must click one of two options. I want to do it in Code.
I tried chd.SwitchToAlert.Accept without success.
My new goal: how can click one of two options between URL-1 and URL-2.

Image desc: Because of not knowing how to upload image,I describe in text.
Based on IP,although physically user is in Switzerland,this website is in US.
Either forward to Switzerland or continue with this US site.
And then below, there're two icons. one is for Switzerland and the other is for US.

'My new revised complete code
Sub ScrapeWTY_Solved()
Dim ss As String
Dim i, j
                
    Dim chd As New Selenium.ChromeDriver

    Dim arr As Variant, item As Variant
    arr = Array("j30a7xlg", "J303A3DB")
               
    chd.Get "https://datacentersupport.lenovo.com/us/ko/warrantylookup#/"
    
For i = 1 To 10
For j = LBound(arr) To UBound(arr)
    
    chd.FindElementByClass("button-placeholder__input").SendKeys arr(j)
    '-----------------------------------------
    ' Wait for the submit button to become clickable
    'chd.WaitElementPresentByCss("#app-standalone-warrantylookup button", timeout:=5000) 'Not working, Why?
    chd.Wait 5000
       
    'chd.SwitchToAlert.Accept 'Not working
    
    ' Click the submit button
    chd.FindElementByCss("#app-standalone-warrantylookup button").Click

    chd.Wait 5000
    Debug.Print i, j, arr(j), chd.FindElementByCss("#app-psp-warranty > div.psp-warranty__body > div > div.psp-warranty__status > div > div.warranty-status__content > div > div.chart-time-bucket > div.chart-expires > p:nth-child(2) > strong").Text
    
    chd.GoBack
    
Next j
Next i

End Sub
2
  • Please post your new bug as a new question. You should also mark Milin Patel's answer as having solved your question. You can find more information about the way we do things here in the help center (sqa.stackexchange.com/help)
    – Kate Paulk
    Jun 30 at 12:14
  • I accepted the answer. I will post a new question when I get the bug case later.
    – rose1205
    Jul 3 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.