2016-04-04 8 views
1

私はこのように、以前のセレクタでそれを連鎖によって要素を見つけるためにしようとしてきた:セレン連鎖CSSセレクタ

WebElement click = driver.findElement(By.cssSelector("td[data-container-for='NumberFrom'] input.k-formatted-value"));  
System.out.println(click.toString()); 

WebElement input1 = click.findElement(By.cssSelector(" ~ input")); 
System.out.println(input1.toString()); 

しかし、私は取得しています:

An invalid or illegal selector was specified 
Element info: {Using=css selector, value= ~ input} 

私はXPathを使用していた場合代わりに、CSS、または単一のCSSセレクタのすべてが正常に動作します:

WebElement input2 = click.findElement(By.xpath("//following-sibling::input")); 
System.out.println(input2.toString()); 

WebElement input3 = driver.findElement(By.cssSelector("td[data-container-for='NumberFrom'] input.k-formatted-value ~ input")); 
System.out.println(input3.toString()); 

私のHTMLは次のとおりです。

<td role="gridcell" data-container-for="NumberFrom"> 
    <span class="k-widget k-numerictextbox" style=""> 
    <span class="k-numeric-wrap k-state-default"> 
     <input class="k-formatted-value k-input" type="text" tabindex="0" style="display: inline;" title="" aria-disabled="false" aria-readonly="false"> 
     <input class="k-input" type="text" name="NumberFrom" data-role="numerictextbox" role="spinbutton" style="display: none;" aria-valuemin="1" aria-valuenow="" aria-disabled="false" aria-readonly="false" data-bind="value:NumberFrom"> 
    </span> 
    </span> 
</td> 

input1セレクタに問題がありますか?

+0

セレニウムは相対セレクタをサポートしているとは思いません。 – BoltClock

+0

XPathを守らなければならないようです。 – Angusiasty

答えて

1

セレンのCSSセレクタで現在のノードを参照する方法はありません

XPathと兄弟軸にとどまるか、完全なCSSセレクタを使用してください。

0

次のセレクタは、あなたのHTMLを使用して私に役立ちます。

input.k-formatted-value ~ input 
+0

申し訳ありませんが、これは私の質問とは無関係です。セレクタを相対的なものとして使用することはできません。 – Angusiasty