Results 1 to 7 of 7

Thread: [RESOLVED] How can I get a compound attribute in selenium+vb6?

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2020
    Posts
    53

    Resolved [RESOLVED] How can I get a compound attribute in selenium+vb6?

    When using ".GetAttribute()" method I can only use 1 single attribute name, it does not support for example (lastElementChild.innerText)
    so I don't know how to formulate a method to get the same result.

    For example, if it is to read the last message of a chat, you could simply use Innertext, but it would get all the dialogs and that would consume more resources than necessary.

    I have switched to using selenium chrome because webbrowser is a bit obsolete for some pages, but without a doubt, using the document method was very simple and easy to work everything with js inputs.

    Now in selenium it is a little different, the element paths are obtained from XPath and at least I don't know how to use JS path.

    I need help with this, thanks!
    Last edited by Maatooh; Nov 24th, 2020 at 09:32 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    Oct 2020
    Posts
    53

    Re: How can I get a compound attribute in selenium+vb6?

    This is the example

    Private WD As SeleniumBasic.IWebDriver
    Const XpathLastmsg As String = "/html/body/div[1]/div/div[2]/div/div[2]/div/div[1]/div/div/div/div/div/section/div/div[3]/div/div[2]/div[3]/div/div"

    Private Sub Command1_Click()
    Run
    End Sub

    Sub Run()
    On Error GoTo Err1
    Set WD = New SeleniumBasic.IWebDriver
    Dim Service As SeleniumBasic.ChromeDriverService
    Dim Options As SeleniumBasic.ChromeOptions
    Set Service = New SeleniumBasic.ChromeDriverService
    With Service
    .CreateDefaultService driverPath:="C:\Users\Maatooh\Documents\Selenium"
    .HideCommandPromptWindow = True
    End With
    WD.New_ChromeDriver Service:=Service
    WD.url = "https://www.twitch.tv/onenava"
    Exit Sub
    Err1:
    MsgBox Err.Description, vbCritical
    Text1 = Err.Description
    End Sub

    Private Sub Command2_Click()
    Text1 = WD.FindElementByXPath(XpathLastmsg).GetAttribute("innerText")
    'Text1 = WD.FindElementByXPath(XpathLastmsg).GetAttribute("lastElementChild.innerText")
    End Sub
    Name:  Sin título.jpg
Views: 513
Size:  34.3 KB

  3. #3
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: How can I get a compound attribute in selenium+vb6?

    You can test it now in the console of Google Chrome

  4. #4
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: How can I get a compound attribute in selenium+vb6?

    You can test it now in the console of Google Chrome

    Few people here use selenium automation. You need to use js to get web content

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2020
    Posts
    53

    Re: How can I get a compound attribute in selenium+vb6?

    Thank you very much for your answer, could you guide me how to do it?

  6. #6
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: How can I get a compound attribute in selenium+vb6?

    WD.FindElementByXPath(XpathLastmsg).text

    Sub jsdemo()
    Dim cd As New ChromeDriver

    jsStr = "document.getElementById('id name').firstChild.setAttribute('src','xxx');"
    jsStr = jsStr & "alert('js ok')"
    cd.ExecuteScript jsStr
    Stop
    End Sub

    Set button = WD.FindElementById("su")

    Debug.Print WD.ExecuteScript("return arguments[0].getAttribute(arguments[1])", button, "value")

    https://www.cnblogs.com/ryueifu-VBA/p/13696693.html
    Last edited by xxdoc123; Nov 24th, 2020 at 10:30 PM.

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2020
    Posts
    53

    Re: How can I get a compound attribute in selenium+vb6?

    Quote Originally Posted by xxdoc123 View Post
    WD.FindElementByXPath(XpathLastmsg).text

    Sub jsdemo()
    Dim cd As New ChromeDriver

    jsStr = "document.getElementById('id name').firstChild.setAttribute('src','xxx');"
    jsStr = jsStr & "alert('js ok')"
    cd.ExecuteScript jsStr
    Stop
    End Sub

    Set button = WD.FindElementById("su")

    Debug.Print WD.ExecuteScript("return arguments[0].getAttribute(arguments[1])", button, "value")

    https://www.cnblogs.com/ryueifu-VBA/p/13696693.html
    Excellent, you made things a lot easier for me friend! thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width