1

I use a mix of VBA and now Selenium to automate some of my office tasks. I have a list of serial numbers (SN) for some devices in Excel, and I am trying to write a script to open Chrome at a Dell support page, input the SN into a field to check the warranty, and return the expiration date into Excel. I cannot bypass the click button operation, usually it would work just fine, alternatively I would use submit, but this time I cannot find the solution.

I know there are APIs to use with Dell that will return the expiration date but I don't want to use the API key for some reasons.

Once I manage to sort out the click, I will pull SN values into an array and loop through instead of using ActiveCell.

Thanks for your suggestions, Karel

Sub CheckDellWarranty()

' Set up Selenium
Dim driver As New WebDriver
driver.Start "chrome"

' Navigate to the specific URL
driver.Get "https://www.dell.com/support/home/fr-fr?app=products"

' Wait for Chrome to load
driver.wait 3000

' Get the value of the currently selected cell in Excel
Dim cellValue As String
cellValue = Application.ActiveCell.value

' Insert the value into the specified field using XPath
Dim inputElement As WebElement
Set inputElement = driver.FindElementByXPath("/html/body/div[5]/div/div[3]/div[1]/div/div/div[2]/div[1]/div[1]/div[1]/div/div/form/input")
inputElement.SendKeys cellValue

' Enable the search button
driver.ExecuteScript "document.getElementById('btn-entry-select').disabled = false;"

' Find the search button by its ID
Dim searchButton As WebElement
Set searchButton = driver.FindElementById("btn-entry-select")

EVEN THOUGH IT CLICKS, THE BUTTON JUST SPINS AND WILL NOT SEARCH. WHEN I OPEN CHROME MANUALLY, THE CLICK ACTION ACTUALLY FINDS THE SN.

If Not searchButton Is Nothing Then
    ' Use JavaScript to trigger the click event on the search button
    driver.ExecuteScript "arguments[0].click();", searchButton
Else
    MsgBox "Failed to locate the button."
End If
Stop

End Sub

Karel
  • 13
  • 2

1 Answers1

0

It doesn't seems that the Search button is ever disabled. The <button> element have 2 descendants:

  • a <div> with style="display: none;
  • a <span> with text Search

You can invoke the click on the <span> with text Search using either of the following locator strategies:

  • Using FindElementByCss:

    driver.FindElementByCss("button#btn-entry-select span")
    
  • Using FindElementByXPath:

    driver.FindElementByXPath("//button[@id='btn-entry-select']//span")
    

Update

Equivalent working Python code snippet:

driver.get("https://www.dell.com/support/home/en-in?app=products")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='entry-main-input-home']"))).send_keys("Latitude 10")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#btn-entry-select span"))).click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the advice, I tried, the problem is not necessarily in locating the element, but I see that the button is behaving differently when Selenium opens the browser vs. when I open the browser manually and interact with the button. So, Selenium will click on the button, but it will only spin for a bit and ultimately nothing happens. I think Dell developers want to prevent people from doing what I am trying to do to force you to register first and offer you services... – Karel Jun 08 '23 at 11:38
  • @Karel Simply add some waits before you attempt the click. I have tested the locators with Python and java both the clients and got them working. – undetected Selenium Jun 08 '23 at 11:41
  • Would you mind pasting the code here? I tried "wait" intervals but there was no change in the behavior. – Karel Jun 08 '23 at 11:46
  • Checkout the answer update with the equivalent working Python code snippet. – undetected Selenium Jun 08 '23 at 11:54
  • Thank you, I tried. In the end it looks like there is a limit to the amount of queries I can do on the Dell's site, I suppose that explains it, first time I ran the macro it worked, now the button just spins for 3 seconds and doesn't do anything. I appreciate your help! It will always find strings as "Latitude" and such, those will trigger a drop-down menu, but it won't be that friendly with one SN after another. – Karel Jun 08 '23 at 13:32