selenium jar包中,在WebElement的接口中,

String getCssValue(String var1);

可以通过标签,获取对应的css值。具体要怎么用呢,如下:
WebElement baidu = driver.findElement(By.id("su"));

su.getCssValue("font-size")
package main.java.aTestDirectory;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;public class TestBaiduElement {String url = "http://www.baidu.com/";@Testpublic void TestElement() {System.out.println("------Begin--------------");System.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe");WebDriver driver = new ChromeDriver();driver.get(url);(new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {public Boolean apply(WebDriver dr) {int index = dr.getPageSource().indexOf("百度一下");if (index != -1) {return true; // 找到,退出等待} else {return false; // 未找到,继续等待}}});WebElement baidu = driver.findElement(By.id("su"));System.out.println("border-bottom-color = " + baidu.getCssValue("border-bottom-color"));System.out.println("border-bottom-style = " + baidu.getCssValue("border-bottom-style"));System.out.println("border-bottom-width = " + baidu.getCssValue("border-bottom-width"));System.out.println("box-sizing = " + baidu.getCssValue("box-sizing"));System.out.println("color = " + baidu.getCssValue("color"));System.out.println("display = " + baidu.getCssValue("display"));System.out.println("text-align = " + baidu.getCssValue("text-align"));System.out.println("background = " + baidu.getCssValue("background"));System.out.println("line-height = " + baidu.getCssValue("line-height"));System.out.println("height = " + baidu.getCssValue("height"));System.out.println("font-family = " + baidu.getCssValue("font-family"));System.out.println("font-size = " + baidu.getCssValue("font-size"));System.out.println("margin-bottom = " + baidu.getCssValue("margin-bottom"));System.out.println("margin-top = " + baidu.getCssValue("margin-top"));System.out.println("margin-left = " + baidu.getCssValue("margin-left"));System.out.println("margin-right = " + baidu.getCssValue("margin-right"));//System.out.println(baidu.getText());driver.quit();System.out.println("------End--------------");}
}

  


打印出来的结果:

通过Chrome校验下,注意要点击Computed下属性才能看出:

转载于:https://www.cnblogs.com/qianjinyan/p/9744237.html

Selenium UI 举例 getCssValue相关推荐

  1. Selenium UI自动化测试(三)IDE—百度个人中心录制实例

    Selenium UI自动化测试(三)百度个人中心查看评分实例详解 录制脚本 菜单点击+添加新的测试用例,弹出测试网址输入百度网址,输入完后点击开始录制 点击右边REC开始录制,进入首页右上角用户名, ...

  2. python selenium UI自动化解决验证码的4种方法

    测试环境 windows7+ firefox50+ geckodriver # firefox浏览器驱动 python3 selenium3 selenium UI自动化解决验证码的4种方法:去掉验证 ...

  3. Selenium UI 自动化获取接口数据

    Selenium UI 自动化获取接口数据 1.前端向接口的传参: 2.捕获到接口返回的内容后,判断前端是否有按照接口返回的内容进行展示 针对第一点,我上家公司是做旅游的,旅客预订完人数.房间数后前端 ...

  4. Python Selenium UI 实现视频自动化播放

    Python Selenium UI 实现视频自动化播放 1.需求:实现某一课程自动播放 from selenium import webdriver from selenium.webdriver. ...

  5. Python+Selenium UI自动化 - 调用JS代码

    当webdriver遇到无法完成的操作时候,这个时候可以使用javascript来完成,webdriver提供了execute_script()接口来调用js代码. 执行js有两种场景: 1.在页面上 ...

  6. Python Selenium UI自动化测试

    1.自动化测试基础 1.1 自动化测试的定义 将人为的测试行为转化为机器自动执行的过程 1.2 自动化测试的目的 减少成本,提高测试效率 减少人为因素对测试的影响 1.3 什么项目适合做自动化测试 项 ...

  7. Robot Framework Selenium UI自动化测试 --- 进阶篇

    回顾:          如果您对Robot Framework Selenium(以下简称RFS)没有基础概念和使用经验,请先阅读入门篇,入门篇对RFS有基础的介绍和使用教程. 展望:       ...

  8. Selenium UI自动化验证码:识别+输入

    思路:使用UI+接口的方式来查找验证码图片和获取验证码元素进行参数输入(用截图方式)(非图片类型验证码无法实现) 我们以访问当当网的注册界面来演示 1.通过selenium定位查找验证码并截图保留 1 ...

  9. Python Selenium UI自动化:滚动条滑动

    文章目录 问题 滑动至固定位置 Window 对象方法 - scrollTo js&python:滑动至固定位置 滑动至元素 元素对象方法 js&python:滑动至元素 问题 在UI ...

最新文章

  1. InputFlinger崩溃问题分析报告
  2. kaptcha验证码组件使用简介
  3. 成功解决UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xba in position 2: illegal multibyte sequence
  4. 《中国人工智能学会通讯》——2.31 跨环境抽象(Abstracting Across Environments)
  5. python 控制系统音量_pygame学习笔记(4):声音控制
  6. windows2003服务器版不能播放声音
  7. 【POJ】1182 食物链
  8. [Abp 源码分析]异常处理
  9. hibernate 基础方法(二)【相关配置详解】
  10. 要重复多少次变成潜意识_什么是潜意识?如何利用潜意识为自己步步高升
  11. 两步完成druid数据库连接池的密文配置
  12. QQ语音对方会听到自己电脑声音
  13. JAVA常用类之日期处理
  14. 配置文件加密 HikariDataSource
  15. 跨境电商卖家应该知道的3个社交媒体营销策略
  16. Chrome如何使用
  17. 发SCI,审稿人意见有一条是“English should be improved”,应该怎样回复?
  18. ARM 汇编指令 DCD
  19. 手机号正则表达式校验,兼容+86,空格和-分隔符等常规手机格式
  20. ssh报错:no matching host key type found. Their offer: ssh-rsa

热门文章

  1. 腾讯云服务器数据盘买多了,腾讯云Windows云服务器数据盘分区和格式化
  2. Queue:poll、offer、element、peek的区别
  3. C++ 运算符重载(一) | 输入/输出,相等/不等,复合赋值,下标,自增/自减,成员访问运算符
  4. 使用github+jsdelivr作为视频床
  5. leetcode191. 位1的个数
  6. leetcode 152 乘积最大子序列
  7. servlet基础总结
  8. 关于uint32_t uint8_t uint64_t 的问题
  9. 使用named_mutex实现读写锁,实现进程之间读共享写独占
  10. C语言 共用体/联合体 union