TRY AND ERROR

気になったこと、勉強したこと、その他雑記など色々メモしていきます。。Sometimes these posts will be written in English.,

Trap on findElement with cssSelector for Facebook WebDriver

github.com


In my case using Facebook WebDriver for Headless browser Testing, there is a trap on findElement with cssSelector.
Assume you want to find the element(s) by css selector that you specify like what their style attribute doesn't have "display:none",
for example you would use WebDriverBy::cssSelector like below.

Facebook WebDriverをテストで使っていて、その時にcssSelectorを使ってfindElementする際のトラップの話。
style属性にdisplay:noneを含まない要素を取得する際、WebDriverBy::cssSelectorでこんな感じに書ける。(部分一致的なやつです)

WebDriverBy::cssSelector("ul li:not([style*='display:none'])")


Although above aims to specify "li" which is visible element located in "ul", you cannot find them if they have half space between "display" and "none". In this case
you have to do insert a half space in the selector like this.

上記はulの中で可視化されているliを特定するためのものだが、displayとnoneの間に半角スペースがあると特定できない、、、
この場合、以下のようにcss selectorに半角スペースを入れる必要がある。

WebDriverBy::cssSelector("ul li:not([style*='display: none'])")

Besides I tried to use ":visible" selector for WebDriverBy::cssSelector(), but It didn't work with log "invalid selector ~".

また、:visibleセレクターも試したけどinvalid selector~~と言われてダメでした。。