Failing to find an element of this field selenium

2019-08-23 12:24发布

I've tried FindElementByName here and it seems like it should recognize this name, but I get a no such element error...

What do I miss? This is on the site Intacct.com. Doesn't seem to be a unique CSS I can turn up, and the relative XPath is non-existent, according to ChroPath. Is there another way I can type into this dang

<input id="filter" class="filter" type="text" name="F_RECORDID" value="" onkeypress="if (event.keyCode == 13) c('.rb','0');" ctype="text">

Sub newCSS()
    Dim bot As New Selenium.WebDriver

    bot.Start "Chrome", "https://www.intacct.com/ia/acct/login.phtml?_ga=2.13247287.1007588550.1536894830-1229002215.1536894830"
    bot.get "/"
    bot.FindElementByXPath("//span[@class='iamenutitle'][contains(text(),'Accounts Payable')]").Click
    bot.FindElementByCss("[menuitemrefno='126']").Click
    bot.SwitchToFrame .FindElementById("iamain")

enter image description here

1条回答
做自己的国王
2楼-- · 2019-08-23 13:03

Try the following to switch to the iframe and then get the element. It is faster across all browsers to use an id, which theoretically is unique to the page. I then show you a method with CSS selector which is faster than using FindElementByName across most browsers and later versions of IE as they are optimized for CSS. If you want to read about the selector speeds please see my answer here. You can also switch to iframes by index.

Option Explicit
Public Sub test()
    Dim driver As New ChromeDriver, ele As Object
    Const URL = "URL"
    With d
        .Start "Chrome"
        .get URL
        'Other steps
        .SwitchToFrame "iamain"
        Set ele = .FindElementById("filter").SendKeys "123"  '.FindElementByCss("[name='F_RECORDID']").SendKeys "123" 
        'OTHER CODE
        .Quit
    End With
End Sub
查看更多
登录 后发表回答