How to send text with in the username field within an iframe using Selenium VBA

五迷三道 提交于 2020-01-24 20:39:04

问题


I am attempting to login in the linked website. It looks straightforward and I have done this successfully in other websites. I can login manually. My code is

Dim bot As New WebDriver
bot.Start "chrome", "https://mbwebedi.mahle.com"
bot.Get "/webedi/jsp/index.jsp"
bot.FindElementByName("Login").SendKeys "ABC123"

I receive the error:

"NoSuchElementError Element not found for Name=Login"

The element's text is:

<input class="loginInput" type="text" name="Login" maxlength="30">`

I can proceed manually at this point, so I don't think focus is the issue. What I am doing wrong?


回答1:


To send a character sequence to the Username field as the the desired element is within an <iframe> so youhave to:

  • First SwitchToFrame.
  • Then locate the element.
  • You can use either of the following Locator Strategies:

    • Using FindElementByCss:

      bot.SwitchToFrame "liefercontent"
      bot.FindElementByCss("input.loginInput[name='Login']").SendKeys "ABC123"
      
    • Using FindElementByXPath:

      bot.SwitchToFrame "liefercontent"
      bot.FindElementByXPath("//input[@class='loginInput' and @name='Login']").SendKeys "ABC123"
      

You can find a relevant discussion in Element doesn't exist although it has ID attribute


tl; dr

Ways to deal with #document under iframe



来源:https://stackoverflow.com/questions/59848281/how-to-send-text-with-in-the-username-field-within-an-iframe-using-selenium-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!