私はいくつかのセレンテストを書いています。私がすでに見つけたWebElement
の祖先を見つけることができる必要があります。CSSクラスを含む祖先ノードを見つけるXPath
これは私がしようとしているが、下の画像は、私が選択したdiv要素が濃い青と私はそれを指す矢印で検索したい1でハイライト表示さ
// checkbox is also a WebElement
WebElement container = checkbox.findElement(By.xpath(
"current()/ancestor-or-self::div[contains(@class, 'x-grid-view')]"));
は結果を返されていないものです。
UPDATE しようとしましたprestomanifestoの提案は、次のエラーを持って、
[cucumber] org.openqa.selenium.InvalidSelectorException: The given selector ./ancestor::div[contains(@class, 'x-grid-view']) is either invalid or does not result in a WebElement. The following error occurred:
[cucumber] [InvalidSelectorError] Unable to locate an element with the xpath expression ./ancestor::div[contains(@class, 'x-grid-view']) because of the following error:
[cucumber] [Exception... "The expression is not a legal expression." code: "51" nsresult: "0x805b0033 (NS_ERROR_DOM_INVALID_EXPRESSION_ERR)" location: "file:///C:/Users/JUAN~1.MEN/AppData/Local/Temp/anonymous849245187842385828webdriver-profile/extensions/fxdriv
アップデート2 本当に奇妙な、でもIDで動作していない
[cucumber] org.openqa.selenium.NoSuchElementException: Unable to locate element:{"method":"xpath","selector":"./ancestor::div[@id='gridview-1252']"}
点のアップデート3
次のXPath作品が、脆い
../../../../../../../*
"現在の()/"の代わりに "./"を試しましたか? – prestomanifesto
@prestomanifesto私はちょうど、何も結果を得ていない...エラーメッセージを追加しました –
表現は完全に合法です。デバッグのために、 'ancestor :: div [1]'、 'ancestor :: div [@ id = 'gridview-1252'] [1]'などを試してください。 – Tomalak