【问题标题】:VBA Getting Run time error '438'object doesn't support this property or methodVBA 获取运行时错误“438”对象不支持此属性或方法
【发布时间】:2017-09-18 18:46:28
【问题描述】:

我正在尝试从 className 获取数据。我收到了错误

运行时错误“438”对象不支持此属性或方法

但我成功地能够从 ID 获取数据。请帮忙。

以下是我尝试过的代码。

Sub Use_Cell_text()
    Dim driver As New FirefoxDriver
    driver.Get "https://www.99acres.com/2-bhk-bedroom-apartment-flat-for-sale-in-jaypee-greens-kosmos-sector-134-noida-942-sq-ft-r1-spid-E31025131?pos=SEARCH&sid=UiB8IFFTIHwgUyB8IzIjICB8IG5vaWRhIzQjIHwgQ1AxIHwgWSB8IzE3IyAgfCAxICMyI3wgIHwgMzIzNzA4ODksMzEwMjUxMzEgfCAxIHwgNyM2IyB8IDEgfCM0MCMgIHw=&fsl=Y"
    With Worksheets("Sheet1")
        Range("B1") = driver.FindElementById("headerDescription").Text
        dd = driver.FindElementById("pdPrice").Text
        dd1 = driver.FindElementById("pricePerUnitArea").Text
        Range("B2") = dd & dd1
        dd3 = driver.findElementByClassName("pdPropAddress").Text
        Range("B3") = dd3
    End With
End Sub

【问题讨论】:

  • 哪一行出现错误?
  • 嗨 braX 我在 dd3 = driver.findElementByClassName("pdPropAddress").Text 处遇到错误
  • 我不确定这是否会有所帮助,但在其他人来回答之前,请阅读以下内容:stackoverflow.com/questions/19189182/…

标签: vba selenium


【解决方案1】:

试试这个。它会为您获取您想要的结果。

Sub Use_Cell_text()
    Dim driver As New FirefoxDriver, post As Object

    driver.get "https://www.99acres.com/2-bhk-bedroom-apartment-flat-for-sale-in-jaypee-greens-kosmos-sector-134-noida-942-sq-ft-r1-spid-E31025131?pos=SEARCH&sid=UiB8IFFTIHwgUyB8IzIjICB8IG5vaWRhIzQjIHwgQ1AxIHwgWSB8IzE3IyAgfCAxICMyI3wgIHwgMzIzNzA4ODksMzEwMjUxMzEgfCAxIHwgNyM2IyB8IDEgfCM0MCMgIHw=&fsl=Y"

    For Each post In driver.FindElementsByClass("pdPropAddress")
        x = x + 1: Cells(x, 1) = post.Text
    Next post
End Sub

【讨论】:

  • 大家好,感谢您的回复!!! , @Mithu 您的代码运行良好,感谢您的大力帮助!!!!
  • 如果有帮助,别忘了将此标记为答案。谢谢。
【解决方案2】:

输入程序行时不要在保留字中输入大写

输入dd1 = driver.findelementbyid("pricePerUnitArea").text,VBA 编辑器会将其更改为dd1 = driver.FindElementById("pricePerUnitArea").Text(FindElementById 中的大写字母)

输入dd3 = driver.findelementbyclassname("pdPropAddress").text,vba编辑器会将其更改为dd3 = driver.findelementbyclassname("pdPropAddress").Text(无大写)

这意味着它无法识别findelementbyclassname

你的线路应该是dd3 = driver.findelementbyclass("pdPropAddress").text

With Worksheets("Sheet1") 行没有用,除非你在范围对象前面放一个点,.Range("B1") ...

With Worksheets("Sheet1")
    .Range("B1") = driver.FindElementById("headerDescription").Text
End With

一样
Worksheets("Sheet1").Range("B1") = driver.FindElementById("headerDescription").Text

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-30
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多