0

I try to use VBA and Selenium to make Automate data entry from excel for my work. However, I am still in the beginning. And I got a problem I want to click on Reserve / Contact Guest, so that will make me to do the Next step of writng my code.

I tried FindElementsByClass & FindElementsByCss & FindElementsById & FindElementsByXpath. But did not work.

This my code:

    Option Explicit
    Dim HJ As New WebDriver
    Sub Test()
    Dim keys As New SeleniumWrapper.keys
   
    HJ.Start "chrome"
    
    'link for webpage
    HJ.Get "http:// "
    
    'Full Screen
    HJ.Wait 1000
    HJ.Window.Maximize
    
    'Username
    HJ.Wait 1000
    HJ.FindElementById("ctl00_SplitterRoot_LoginContent_tbUserName_I").Click
    HJ.FindElementById("ctl00_SplitterRoot_LoginContent_tbUserName_I").SendKeys ("")
    
    'Password
    HJ.Wait 1000
    HJ.FindElementById("ctl00_SplitterRoot_LoginContent_tbPassword_I_CLND").Click
    HJ.FindElementById("ctl00_SplitterRoot_LoginContent_tbPassword_I").SendKeys ("")
    
    'Checkbox
    HJ.Wait 1000
    HJ.FindElementById("ctl00_SplitterRoot_LoginContent_chkKeepMeIn").Click
    
    'Log in
    HJ.Wait 1000
    HJ.FindElementById("ctl00_SplitterRoot_LoginContent_btnLogin_CD").Click
    
    'Only one page
    HJ.Wait 1000
    HJ.FindElementById("ctl00_SplitterRoot_chkPin_S_D").Click
    
    'CRM
    HJ.Wait 1000
    HJ.FindElementById("ctl00_SplitterRoot_RootContent_ASPxFormLayout_cmdModule7").Click
    
    'Reserve / Contact Guest (HERE THE PROBLEM With All My Tries)
    HJ.Wait 1000
    
    'HJ.FindElementByXPath("//*[@id='ctl00_contentSplitter_menuMain_I0i0_']").Click
    'HJ.FindElementById("ctl00_contentSplitter_menuMain_I0i0_").Click
    'Set CRMs =HJ.FindElementByClass("dxnb-item dxnb-link dxnb").Click
    'For Each CRM In CRMs
    ''Debug.Print CRM.Text
    'Next CRM
 'HJ.FindElementByXPath("/html/body/form/div[3]/table[1]/tbody/tr/td[1]/div/div/ul/li/ul/li[1]/span").Click
    'HJ.FindElementByCss("#ctl00_contentSplitter_menuMain_I0i0_ > span").Click
    'HJ.FindElementsByClass("ctl00_contentSplitter_menuMain_I0i0_")(1).Click
    'HJ.FindElementById("ctl00_contentSplitter_Maincontent_imAddNew").Click
   
    
    End Sub

I want to click to Reserve / Contact Guest:

enter image description here

This is webpage:

enter image description here enter image description here

1 Answers1

0

To click() on the element with text as Reserve / Contact Guest you can use either of the following locator strategies:

  • Using FindElementByXPath and the text Reserve / Contact Guest:

    HJ.FindElementByXPath("//span[@class='dx-vam' and contains(., 'Reserve / Contact Guest')]").Click
    
  • Using FindElementByXPath and the text Reserve:

    HJ.FindElementByXPath("//span[@class='dx-vam' and starts-with(., 'Reserve')]").Click
    
  • Using FindElementByXPath and the text Contact Guest:

    HJ.FindElementByXPath("//span[@class='dx-vam' and contains(., 'Contact Guest')]").Click
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I try All of them , but they did not work. I got this note: run-time error '7': No SuchElementError Element not found for Xpath="//span[@class='dx-vam' and contains(., 'Reserve / Contact Guest')] – Khadijah Alsaihati Feb 27 '22 at 10:22