访问2016,刚刚从I.E DOM切换到Selenium / Chrome :)需要在自动提交表单/网页后获取eBay列表ID号 - 这部分工作真的很棒!使用下面的XPath或Css行获取运行时428“对象不支持此属性或方法”。错误时的getItemID值显示为null(getItemID =“”)
Select Case [Forms]![SettingsForm]![ListingOptionsFrame]
Case 1
'Listing Item --------------- AutoListOption-------------------------
Dim getText As String
Me.ItemID = getItemID
driver.FindElementByXPath("//input[@value='List item']").Click
PauseTimed (10) 'submitting Listing to eBay
getText = driver.FindElementByXPath("//*@id='Email']").getAttribute("data-itemid") '.getText() in place of .getAttribute 428's
'getText = driver.FindElementByCss("#Email").getAttribute("data-itemid") '.getText() in place of .getAttribute 428's as well
Case 2
为了简洁起见,ebay的HTML缩短了。需要来自data-itemid的“值”。
<a id="Email" ...... data-itemid="143211121121"></a>
如有必要,还可以从<span>获取“值”。我也有类似的428错误,需要使用Right()来获取“值”。
一个想法? 428错误可能来自页面重新加载还是提交后的弹出窗口?页面的地址不会改变。如果你能指出我的方向,我会非常感激吗?
vba selenium中的方法只是Attribute()
,你现有的错误代码应该是438。
driver.FindElementByXPath("//*@id='Email']").Attribute("data-itemid")
您正在使用webElement,对于VBA实现,它具有不同的语法。在IE中通过Microsoft Internet Controls使用节点时,可以使用getAttribute
语法,该语法与Element
接口的javascript方法相同。
Option Explicit
Public Sub Example()
Dim d As WebDriver
Const URL As String = "https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors"
Set d = New ChromeDriver
With d
.Start "Chrome"
.get URL
Debug.Print .FindElementByCss("#edit-history-menu").Attribute("type")
.Quit
End With
End Sub