简体   繁体   English

Behat / Selenium-元素可见,但对于测试框架不可见

[英]Behat / Selenium - Element is visible but not visible for testing framework

I am not sure is it Behat or Selenium issue, but on Google's account page where user can manage and remove connected to account apps - I can not actually delete one with Behat, because it thinks that elements in dialog confirming removing are invisible. 我不确定是Behat还是Selenium问题,但是在Google的帐户页面上,用户可以管理和删除连接到帐户应用程序的帐户-我实际上无法使用Behat删除帐户,因为它认为对话框中确认删除的元素是不可见的。

The page is here: https://security.google.com/settings/security/permissions 该页面位于: https : //security.google.com/settings/security/permissions

If you have any connected to your google account app (like Quora or anything else) click Remove you will see confirmation dialog, it has button OK in it, I can select this element with Behat, but $el->isVisible() returns false . 如果您有任何连接到您的Google帐户应用程序(例如Quora或其他任何东西),请单击Remove您将看到确认对话框,其中包含OK按钮,我可以使用Behat选择此元素,但是$el->isVisible()返回false

Do not know what to do. 不知道该干什么。 Any ideas? 有任何想法吗?

在此处输入图片说明

OK is not a button, but: 确定不是按钮,而是:

<content class="Nb"><span>OK</span></content>

So you cannot select it with "press "OK"". 因此,您无法通过“按“确定””来选择它。 If you have a proper selector, you may wait for button to appear (I gue), or use: 如果选择器正确,则可以等待按钮出现(我猜),或使用:

$this->getSession()->wait($time, '<javascript condition>');

inside your context class. 在您的上下文类中。

Hope this helps. 希望这可以帮助。

Can not say why it is invisible but you can just go ahead and click it with JavaScript , like this: 不能说为什么它invisible但是您可以继续使用JavaScript单击它,如下所示:

    $cssSelector = "div[role='dialog'] div[role='button'][autofocus] SPAN";

    $js  = 'var event = document.createEvent("HTMLEvents");';
    $js .= 'var element = document.querySelectorAll("'.$cssSelector.'")[0];';
    $js .= 'event.initEvent("click", true, true);';
    $js .= 'event.eventName = "click";';
    $js .= 'element.dispatchEvent(event);';

    $this->getSession()->executeScript($js);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM