2016-08-12 43 views
0

enter image description here我有一個測試場景來驗證輸入元素中的佔位符文本的顏色。 我不知道如何使用硒來做到這一點。 我的HTML使用硒webdriver獲取佔位符文本顏色

<div class="pe-input"> 
    <label for="input-text-active-PH">Active Basic text input with placeholder :</label> 
    <input type="text" id="input-text-active-PH" placeholder="Basic text input field" value=""> 
</div> 

這是CSS

.pe-input input::-webkit-input-placeholder, 
.pe-input textarea::-webkit-input-placeholder { 
    font-style: italic; 
    color: #6d6d6d; } 

有人可以幫助我如何獲取使用硒用java中的佔位符文本顏色?

+0

你能展示你自己的嘗試嗎? – pistache

+0

你的意思是你想要標籤文本顏色或輸入屬性佔位符文本顏色? –

+0

我在selenium庫中看不到選項以獲取佔位符的css顏色。我只能得到輸入元素中的輸入顏色,而不是佔位符的顏色。 – aspiringqa

回答

1

要想從CSS的價值,u可以使用getCssValue()方法,如下面的代碼:

String color = driver.findElement(By.cssSelector("input#input-text-active-PH")).getCssValue("color"); 

這將返回該元素的CSS顏色值。

+0

您的聲明將返回輸入元素的顏色,但不包含佔位符文本。 – aspiringqa