温馨提示:本文翻译自stackoverflow.com,查看原文请点击:selenium - Verify CSS Value in Codeception Webdriver
codeception selenium webdriver

selenium - 在Codeception Webdriver中验证CSS值

发布于 2020-05-19 12:13:00

我想验证在Codeception Acceptance测试中使用Selenium Webdriver时,从CSS样式表中通过绝对位置移动元素的像素数量。在我的示例中,当背景图片绝对位于右侧50px时,界面显示元素为“开”。

虽然Codeception没有默认命令,但是您可以使用ExecuteInSelenium或Helper,我相信它将允许该操作。

为ExecuteInSelenium的代码接收提供的示例是:

$I->executeInSelenium(function(\WebDriver $webdriver) {
  $webdriver->get('http://google.com');
});

我要验证的CSS值示例是在元素上的“正确”值。

.on_switch {
    position: absolute;
    right: 50px;
}

HTML元素列出为:

<div class="on_switch"></div>

由于类名重复,在其他元素上,我需要使用Xpath并相信以下内容将为我提供像素数量的值,但不确定如何验证该值是否为50px以允许此测试步骤通过。

$I->executeInSelenium(function(\WebDriver $webdriver) {
  $webdriver->driver.findElement(By.xpath("myxpath")).getCssValue("right");
});

我在网上很难找到示例,我们将为您提供任何帮助。

查看更多

提问者
Uberfloyd
被浏览
11
mfsi_krushnas 2014-09-03 14:02

您为什么不尝试使用此“ VisualCeption”。它是Codeception的附加组件。我相信它可以解决您的问题。

https://github.com/DigitalProducts/codeception-module-visualception