1

I am having trouble with code while trying to take the class name. I have tried and run time error 32 is appearing as:

InvalidSelector Error: compund class names not permitted

Maybe somebody canhelp with the code below. I have chrome browser 103.5060.114 but web driver 103.5060.56 . I could not find other driver to wnload.

HTML:

<span dir="auto" title="Customer" class="ggj6brxn gfz4du6o r7fjleex g0rxnol2 lhj4utae le5p0ye3 l7jjieqr i0jNr">Customer</span>

VBA code:

Sub iselementpresenttest()
    
Dim bot As New WebDriver
Dim ks As New Keys

'Init New Chrome instance & navigate to WebWhatsApp
bot.Start "chrome", "https://web.whatsapp.com/"
bot.Get "/"
bot.Window.Maximize
MsgBox "Please scan the QR code. After you are logged in, please confirm this message box by clicking 'ok'"
bot.Wait (3500)
        
'        If bot.FindElementByClass("_2qo4q _3NIfV") = 1 Then
'    Debug.Print "true"
'End If
        
        If bot.FindElementByClass("ggj6brxn gfz4du6o r7fjleex g0rxnol2 lhj4utae le5p0ye3 l7jjieqr i0jNr") = 1 Then
'                If bot.FindElementByXPath("//*[@id='pane-side']/div/div/div/div[11]/div/div/div[2]/div[2]/div[1]/span/div/span") = 1 Then
    Debug.Print "true"
End If
'        If bot.FindElementsByXPath("//*[@id='main']/div[3]/div/div[2]/div[3]/div[20]/div/div[1]/div[1]/div[2]/div/div/span").Count > 0 Then
    If bot.FindElementsByXPath("//*[@id='main']/div[3]/div/div[2]/div[3]/div[20]/div/div[1]/div[1]/div[2]/div/div/span").Count > 0 Then
        bot.TakeScreenshot.ToExcel.PasteSpecial (xlPasteAll)
        
            bot.Quit
            MsgBox "Yes"
        Else
            bot.Quit
            MsgBox "NO"
        End If
        
    End Sub

My aim is to take the send receive whatsapp icon to the excel sheet

braX
  • 11,506
  • 5
  • 20
  • 33
xlmaster
  • 659
  • 7
  • 23

1 Answers1

1

You need to take care of a couple of things here:

  • The classnames of the <span> looks dynamic and and may change sooner or later, even may be next time you access the application afresh.
  • Selenium doesn't permit compund class names

Solution

To identify the element you can use the following locator strategies:

  • Using FindElementByCss:

    bot.FindElementByCss("span[title='Customer']")
    
  • Using FindElementByXPath:

    bot.FindElementByXPath("//span[@title='Customer' and text()='Customer']")
    
xlmaster
  • 659
  • 7
  • 23
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • For first method FindElementByCss it writes Object does not support this method If bot.FindElementByCss("span[title='Customer']") = 1 Then – xlmaster Jul 16 '22 at 23:16
  • Second method is separate i guess. Both methods are given the same object does not support this method. Maybe you other way, how to take check mark read receipt from whatsapp via VBA to excel sheet? – xlmaster Jul 16 '22 at 23:22
  • _**Object does not support this method**_ isn't a Selenium error. Check [this](https://excelchamps.com/vba/object-doesnt-support-this-property-or-method-error-438/) and [this](https://stackoverflow.com/questions/21557683/vba-object-doesnt-support-this-property-or-method) discussion. – undetected Selenium Jul 16 '22 at 23:27
  • `bot.FindElementByCss()` or `bot.FindElementByXPath()` would always return the first matching element. So `If element = 1 Then` doesn't seems to be rational. Instead you can _`If bot.FindElementByCss("span[title='Customer']") Then`_ – undetected Selenium Jul 16 '22 at 23:30
  • I want to write a for loop to find the customer first then go inside that div block and look for ElementByCss. But it gives me error when I this code. It writes element out of screenshot. bot.FindElementByXPath("//span[@data-testid='status-dblcheck']").TakeScreenshot.Copy Sheets(1).Cells(5, 5).Paste – xlmaster Jul 16 '22 at 23:45
  • 1
    Sounds to be a different question. Can you raise a new question with your new requirement please? – undetected Selenium Jul 16 '22 at 23:48
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246500/discussion-between-xlmaster-and-undetected-selenium). – xlmaster Jul 16 '22 at 23:50
  • Let's discuss the issue in [Selenium](https://chat.stackoverflow.com/rooms/223360/selenium) room. – undetected Selenium Jul 16 '22 at 23:51