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.pswp.cn/news/450531.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/450531.shtml
英文地址,請注明出處:http://en.pswp.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 --…