使用父 selenium xpath 在 dom 中定位元素
Locating element in the dom with parent selenium xpath
我正在尝试 select 来自 table td 元素的复选框,但 Selenium 未找到该元素,这是我的 xpath 定位器 "//*/td/a[contains(.,'Samsung Galaxy Note 10.1')]//parent::td[last()]/input[@type='checkbox']"
。我需要单击带有类型复选框的输入字段,具体取决于 Galaxy 文本中的文本。
你可以使用这个 xpath
//a[contains(text(),'Samsung GALAXY Note 10.1')]/../following-sibling::td[last()]//input[@type='checkbox']
您要找的是Samsung Galaxy Note 10.1
,而是Samsung GALAXY Note 10.1
如果这是唯一的 //a[contains(text(),'Samsung GALAXY Note 10.1')]
那么我提供的 XPath 应该可以工作。
元素是 JavaScript enabled element so to click() on the element you need to induce for the elementToBeClickable()
and you can use either of the following :
使用 xpath 和 index:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(., 'Samsung GALAXY Note 10.1')]//following::td[12]//input[starts-with(@id, 'ContentModify') and @type='checkbox']"))).click();
使用 xpath 和 last():
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='ContentRowOdd']/td[.//a[contains(., 'Samsung GALAXY Note 10.1')]]//following::td[last()]//input[starts-with(@id, 'ContentModify') and @type='checkbox']"))).click();
我正在尝试 select 来自 table td 元素的复选框,但 Selenium 未找到该元素,这是我的 xpath 定位器 "//*/td/a[contains(.,'Samsung Galaxy Note 10.1')]//parent::td[last()]/input[@type='checkbox']"
。我需要单击带有类型复选框的输入字段,具体取决于 Galaxy 文本中的文本。
你可以使用这个 xpath
//a[contains(text(),'Samsung GALAXY Note 10.1')]/../following-sibling::td[last()]//input[@type='checkbox']
您要找的是Samsung Galaxy Note 10.1
,而是Samsung GALAXY Note 10.1
如果这是唯一的 //a[contains(text(),'Samsung GALAXY Note 10.1')]
那么我提供的 XPath 应该可以工作。
元素是 JavaScript enabled element so to click() on the element you need to induce elementToBeClickable()
and you can use either of the following
使用 xpath 和 index:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(., 'Samsung GALAXY Note 10.1')]//following::td[12]//input[starts-with(@id, 'ContentModify') and @type='checkbox']"))).click();
使用 xpath 和 last():
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='ContentRowOdd']/td[.//a[contains(., 'Samsung GALAXY Note 10.1')]]//following::td[last()]//input[starts-with(@id, 'ContentModify') and @type='checkbox']"))).click();