Selenium UI 举例 getCssValue

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/450531.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java集合框架中contains(),containsKey()和containsValue()的用法

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 java集合框架中contains(),containsKey()和containsValue()的用法&#xff1a; List集合的contains()方法用于判断集合中包不包含某个元…

敏捷视频

规模化极限编程的关键抓手&#xff1a;验收条件https://mp.weixin.qq.com/s/aHlSxpMx7DTQXaoEgcAQ3g 5分钟让你子解持续集成https://www.bilibili.com/video/BV1SK411W77W/?spm_id_fromtrigger_reload 5分钟让你学会返工率降低1倍的神技--开卡、验卡https://www.bilibili.com/…

提问的智慧

提问的智慧转载于:https://www.cnblogs.com/whigym/p/10028642.html

C语言指针和数组概述

几乎每次讲课讲到指针和数组时&#xff0c;我总会反复不停的问学生&#xff1a;到底什么是指针&#xff1f;什么是数组&#xff1f;他们之间到底是什么样的关系。从几乎没人能回答明白到几乎都能回答明白&#xff0c;需要经历一段“惨绝人寰”的痛。指针是C/C的精华&#xff0c…

Linux tee的花式用法和pee

1.tee多重定向 tee [options] FILE1 FILE2 FILE3... tee的作用是将一份标准输入多重定向&#xff0c;一份重定向到标准输出/dev/stdout&#xff0c;然后还将标准输入重定向到每个文件FILE中。 例如&#xff1a; $ cat alpha.log | tee file1 file2 file3 | cat $ cat alpha.log…

[CF893F]Subtree Minimum Query

题目大意&#xff1a; 给你一颗有根树&#xff0c;点有权值&#xff0c;m次询问&#xff0c;每次问你某个点的子树中距离其不超过k的点的权值的最小值。&#xff08;边权均为1&#xff0c;点权有可能重复&#xff0c;k值每次询问有可能不同&#xff0c;强制在线&#xff09; 做…

mac电脑快捷键(持续更新)

1、快速查找软件 commandspace 2、显示/隐藏文件夹 shiftcmmand. 3、路径输入 commandshiftg 4、快速打开软件 commandtab 5、截图 commandshift3 commandshift4 6、注销 Command-Shift-Q 7、强制注销 ommand-Shift-Option-Q 8、睡眠 controlshift电源键 9、选…

C语言typedef关键字—伟大的缝纫师

关于马甲的笑话。有这样一个笑话&#xff1a;一个猎人在河边抓捕一条蛇&#xff0c;蛇逃进了水里。过一会&#xff0c;一个乌龟爬到岸边。猎人一把抓住这个乌龟&#xff0c;大声的说道&#xff1a;小样&#xff0c;别你为你穿了个马甲我就不认识你了&#xff01;typedef 关键字…

将网桥的配置写进去/etc/sysconfig/network-scripts/ifcfg-xxx

有时候需要使用网桥命令比如brctl设置一些网桥的属性&#xff0c;而这些方式能否同样写进去配置文件使其永久开机生效。 答案是不行的&#xff0c;也同样找过Ubuntu的&#xff0c;其实Ubuntu可以实现&#xff0c;参考&#xff1a;http://manpages.ubuntu.com/manpages/cosmic/m…

phpstorm如何回滚。并取消本地提交

1、现在我提交到本地 当前git版本为4b53dca9 上一版本为965cdf14 2、现在执行回滚操作&#xff0c;取消本地提交 版本复制到这里&#xff0c;点击reset就会回滚了 如需使用git命令操作&#xff0c;请参考链接https://blog.csdn.net/qq_35774849/article/details/107313193

windows server 2008 R2 x64 基础知识(2)

一、防火墙设置 1.windows防火墙的种类&#xff1a; 1)工作组网络环境 2)域网络环境 2.防火墙的配置 1)打开管理工具&#xff1a;win->管理工具->高级安全windows防火墙 2)管理配置&#xff1a; (1)防火墙的数据流类型 a.入站流量&#xff1a;外部访问内部分流量 b…

SOA 说明,解析

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 一直对SOA这个概念不甚明了&#xff0c;再度记录下&#xff1a; 一、是一个面向服务的架构&#xff0c;是一种思想、规则。而不是一个确…

Windows API 第二篇 SHGetSpecialFolderPath

BOOL SHGetSpecialFolderPath( HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate ); 参数解释&#xff1a; hwndOwner&#xff1a;Handle to the owner wind…

面向对象—的__new__()方法详解

[Python] Python 之 __new__() 方法与实例化 __new__() 是在新式类中新出现的方法&#xff0c;它作用在构造方法建造实例之前&#xff0c;可以这么理解&#xff0c;在 Python 中存在于类里面的构造方法 __init__() 负责将类的实例化&#xff0c;而在 __init__() 启动之前&#…

git使用回滚,清除暂缓区,解决冲突(持续更新)

1、git restore --staged <文件> 清除暂缓区文件名 2、git reset --hard <版本号> 回滚到上一版本 如看PHPstrom如何操作请参考https://blog.csdn.net/qq_35774849/article/details/107312658 3、解决冲突 &#xff08;1&#xff09;使用默认的解决冲突 打开…

14.安全

1.基本概念 安全问题的产生&#xff1a; 互联网作为商业交易的工具快速发展&#xff0c;越来越多的公司提供网络交易服务。很多商业活动在网上进行当前&#xff0c;成千上万的网民在网上进行各种活动的同时&#xff0c;也在网上传递其个人信息每天在网上发生各种各样的商业活动…

C语言enum关键字

很多初学者对枚举(enum)感到迷惑&#xff0c;或者认为没什么用&#xff0c;其实枚举(enum)是个很有用的数据类型。一、枚举类型的使用方法 一般的定义方式如下&#xff1a;enum enum_type_name{ENUM_CONST_1,ENUM_CONST_2,...ENUM_CONST_n} enum_variable_name;注意&#xff1a…

Dubbo 需求、架构、使用Demo

只是整理下方便自己记录 内容全部来自官网&#xff1a;http://dubbo.io/books/dubbo-user-book/preface/usage.html 一、需求 在大规模服务化之前&#xff0c;应用可能只是通过 RMI 或 Hessian 等工具&#xff0c;简单的暴露和引用远程服务&#xff0c;通过配置服务的URL地址进…

Ubuntu安装之python开发

Ubuntu安装之python开发 什么&#xff1f;&#xff1f;Ubuntu(乌班图)开发&#xff1f;不会用&#xff1f;&#xff1f;怎么进行python开发&#xff1f;&#xff1f;&#xff1f; 乌班图操作系统下载地址&#xff1a;http://releases.ubuntu.com/18.04/ubuntu-18.04.1-desktop-…

vimdiff和vim-fugitive安装,使用教程

1、vimdiff的安装 在终端执行 git config --global merge.tool vimdiff git config --global merge.conflictstyle diff3 git config --global mergetool.prompt false git config --global diff.tool vimdiff git config --global difftool.prompt false git config --…