我正在写一些Selenium测试,我需要能够找到我已经找到的WebElement的祖先.
这是我正在尝试但没有返回任何结果
// checkBox is also a WebElement WebElement container = checkBox.findElement(By.xpath( "current()/ancestor-or-self::div[contains(@class,'x-grid-view')]") );
下面的图像显示了我选择的深蓝色突出显示的div和我想要用箭头指向它的那个.
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有效,但很脆弱
../../../../../../../*