Asserting an element is focused

后端 未结 7 912
傲寒
傲寒 2020-12-16 18:50

According to the How do I assert an element is focused? thread, you can check if an element is focused by switching to an activeElement() and assert this is the

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 19:29

    It's weird that it's expecting a promise only and could not handle a webdriver element... I had the same HUGE stacktrace as you.

    Anyway, would you accept this kind of solution: send a "dumb" promise with a nice comment to justify why you had to do that. It's more a workaround than a semantic solution I admit.

    expect(page.element.getInnerHtml())
      .toEqual(browser.driver.switchTo().activeElement().getInnerHtml());
    

    It's working for me ;)

    EDIT: Bonus answer

    The reason you can't call expect with a WebElement comes from the Webdriver Control Flow Principle (I'm sure you already know about) and this line in jasminewd, the adapter for jasmine to Webdriver developped and used by Protractor ;)

提交回复
热议问题