热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

断言SeleniumIDE中的元素颜色-AssertelementcolorinSeleniumIDE

Imtryingtosetupatestautomationthatwillassertanelementcolorwhenclicked.However,Icou

I'm trying to setup a test automation that will assert an element color when clicked. However, I couldn't find the right way to do it. I'm a selenium newbie, I have tried every possible way to do it but failed.

我正在尝试设置一个测试自动化,它将在单击时确定元素的颜色。然而,我找不到正确的方法。我是一个硒新手,我尝试了所有可能的方法去做,但是失败了。

HTML:

HTML:


CSS:

CSS:

.imweb #mgifting-dialog .mg-friends .friend.selected, .imweb #mgifting-dialog .mg-friends .non-friend.selected {
  background-color: #9DD4FD;
}

2 个解决方案

#1


2  

IMHO the idea be the following: we simply need to get css property(color, in particulat) of element before click. and get css property(color ) of the element after click on it.

我的想法是这样的:我们只需要在单击之前获得元素的css属性(尤其是颜色)。并在单击后获取元素的css属性(颜色)。

so it be like (I work on java and we will execute a piece of Javascript using jsExecutor to implement getColor function. It will take css selector of the element. And get return its color):

就像(我在java上工作,我们将使用jsExecutor执行一段Javascript来实现getColor函数。它将采用元素的css选择器。并返回它的颜色):

public String jsGetColor(String css){
        JavascriptExecutor js = (JavascriptExecutor) driver;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("var x=$(\'"+css+"\');");
        stringBuilder.append("return x.css('color')");
        //stringBuilder.append("return x.css('background-color')");
        String res= (String) js.executeScript(stringBuilder.toString());
        return res;
    }

String cssSelectorLink="a[class='mg-friend-12345 friend selected']";
WebElement linkToClick = driver.findElemebt(By.cssSelector(cssSelectorLink));
String colorBeforeClick = jsGetColor(cssSelectorLink);
linkToClick.click();
String colorAfterClick = jsGetColor(cssSelectorLink);
Assert.assertFalse(colorBeforeClick.equals(colorAfterClick));

Hope it be helpful for you.

希望对你有帮助。

#2


1  

well I work in intelij IDEA. So setUp to write selenium tests e.g. be the following:

我在intelij创意公司工作。因此,设置编写selenium测试,例如:

1) install maven

1)安装maven

  • Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to the directory you wish to install Maven 3.0.4. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.0.4 will be created from the archive.
  • 解压分发归档文件,即apachemail -3.0.4-bin。压缩到希望安装Maven 3.0.4的目录。这些说明假设您选择C:\Program Files\Apache软件基金会。将从存档中创建子目录apachemail -3.0.4。
  • Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.0.4. Be sure to omit any quotation marks around the path even if it contains spaces. 
  • 添加M2_HOME环境变量通过开放系统属性(徽标键+停顿),选择“高级”选项卡,和“环境变量”按钮,然后在用户变量中添加M2_HOME变量值\ apache-maven-3.0.4 C:\Program Files\Apache软件基础。即使路径包含空格,也要忽略路径周围的引号。
  • In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
  • 在相同的对话框中,在用户变量中添加M2环境变量,值为%M2_HOME%\bin。

2) install jdk 3) enter image description here

2)安装jdk 3)

4) verify that all environment variables you've set properly enter image description here 5) run intelij IDEA select Project structure to set up installed JDK enter image description here 6) press New.select jsdk. write path where we installed java, e.g C:\Program Files\Java\jdk1.6.0_29 enter image description here 7)create new project from scratch enter image description here 8) maven module enter image description here 9) enter image description here 10) enter image description here 11) add to POM appropriate dependencies: enter image description here

4)验证您正确设置的所有环境变量是否运行intelij IDEA选择项目结构,以设置已安装的JDK。选择jsdk。写入路径,安装java, e。g C:\Program Files\Java\ jdk1.6.0_29 7)从头开始创建新项目8)maven模块9)10)11)添加POM适当的依赖关系:

   
 org.seleniumhq.selenium 
selenium-java 
2.24.1 
 

12) if still someting underline with red line , press alt+enter on it >> idea should automatically suggest autoimport.

12)如果仍有红线下划线,按alt+enter键>>建议自动导入。

13)test structure in the project enter image description here

13)项目测试结构

14)common structure of selenium test

14)硒测试的共同结构

import com.thoughtworks.selenium.SeleneseTestBase;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.concurrent.TimeUnit;

public class HomePageTest extends SeleneseTestBase{

    static WebDriver driver;

    @Before
    public void openFirefox(){

        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    }

    @Test
    public void testHomePage(){
        driver.get("https://www.google.by/");
        WebElement search = driver.findElement(By.xpath("//*[@id=\"gbqfq\"]"));
        search.sendKeys("laptop");
        search.submit();

    }

    @After
    public void closeFirefox(){
        // driver.quit();
    }
}

15) also don't forget that you can export your created test in selenium IDE as JUNIT4- selenium and open them in IDEA enter image description here

15)也不要忘记,您可以将在selenium IDE中创建的测试导出为JUNIT4- selenium,并在IDEA中打开它们

Regards

问候


推荐阅读
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • 本文介绍了闭包的定义和运转机制,重点解释了闭包如何能够接触外部函数的作用域中的变量。通过词法作用域的查找规则,闭包可以访问外部函数的作用域。同时还提到了闭包的作用和影响。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • javascript  – 概述在Firefox上无法正常工作
    我试图提出一些自定义大纲,以达到一些Web可访问性建议.但我不能用Firefox制作.这就是它在Chrome上的外观:而那个图标实际上是一个锚点.在Firefox上,它只概述了整个 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
author-avatar
慕容盼烟迎曼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有