Vba硒代码从Li类获取数据 [英] Vba selenium code to get data from Li class

查看:80
本文介绍了Vba硒代码从Li类获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从具有相同Class的li获取数据,以下是我尝试过但未收到任何输出的代码.

I am trying to get data from li having same Class below is the code which i have tried but did not received any output.

请纠正我错了的地方.

我的VBA代码:

Sub Class_Initialize()
Set driver = CreateObject("Selenium.FirefoxDriver")
driver.get "url"
driver.Window.Maximize
Dim dd As Variant
dd = driver.findElementsByClass("oas_columns ng-binding")(2).Text
Range("A" & Rows.Count).End(xlUp).Offset(1) = dd

'In column A i require output Abhay 28566207

dd = driver.findElementsByClass("oas_columns ng-binding")(3).Text
Range("B" & Rows.Count).End(xlUp).Offset(1) = dd

'In column B i require output Brick Field Shelters

dd = driver.findElementsByClass("oas_columns ng-binding")(4).Text
Range("C" & Rows.Count).End(xlUp).Offset(1) = dd

'In column C i require output 2018-02-12

End Sub

我的HTML代码:

<ul class="oas_columnsWrapper">
<li class="oas_columns ng-binding" ng-show="vm.data">1.</li>
<li class="oas_columns ng-binding">Abhay 28566207</li>
<li class="oas_columns ng-binding">Brick Field Shelters</li>
<li class="oas_columns ng-binding">2018-02-12</li>
<li class="oas_columns ng-binding">3,868</li>
<li class="oas_columns ng-binding">33</li>
<li class="oas_columns ng-binding">0.85%</li>
<li class="oas_columns semiBold active">ACTIVE</li>
<div class="oas_columns" ng-show="x['responseCount']"><a href="/do/my99acres/homepage/route/all_responses/ITOA-8157" ng-click="trackGA('Manage Listings', 'OnClick', 'ML_ShowResponse', '');" ui-sref="root.response({filter:'ITOA' + '-' + 8157})" ui-sref-opts="{reload:true}" class="ng-binding">4 Responses</a></div><li class="oas_columns oas_viewReportBtn" id="oas_viewReportBtn0" ng-click="vm.viewReport($index,$event);">View Report</li></ul>

推荐答案

要从<li>标记获取文本,可以使用以下

To get the text from the <li> tags you can use the following Locator Strategies :

  • Abhay 28566207:

dd = driver.FindElementByXPath("//ul[@class='oas_columnsWrapper']//following::li[2]").Text
//or
dd = driver.FindElementByXPath("//ul[@class='oas_columnsWrapper']//following::li[2]").Attribute("innerHTML") 

  • Brick Field Shelters:

    dd = driver.FindElementByXPath("//ul[@class='oas_columnsWrapper']//following::li[3]").Text
    //or
    dd = driver.FindElementByXPath("//ul[@class='oas_columnsWrapper']//following::li[3]").Attribute("innerHTML")
    

  • 2018-02-12:

    dd = driver.FindElementByXPath("//ul[@class='oas_columnsWrapper']//following::li[4]".Text
    //or
    dd = driver.FindElementByXPath("//ul[@class='oas_columnsWrapper']//following::li[4]".Attribute("innerHTML")
    

  • 这篇关于Vba硒代码从Li类获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆