【发布时间】:2017-11-27 20:45:17
【问题描述】:
我正在努力解决 xpath 问题。代码包含在正在处理的 iframe 中:
<div _ngcontent-c10 class="panel panel-info">
<div _ngcontent-c10 class="panel-heading"> ABC Output </div>
<div _ngcontent-c10 class="panel-body">
<form _ngcontent-c10 novalidate class="ng-untouched ng-pristine ng-valid">
<div _ngcontent-c10 class="row">
<table _ngcontent-c10 class="table tb-striped">
<tbody _ngcontent-c10>
<tr _ngcontent-c10="">
<td _ngcontent-c10="" class="td-fixed-width-35">
<label _ngcontent-c10="">
<input _ngcontent-c10="" type="checkbox" value="" class="ng-untouched ng-pristine ng-valid">
</label>
</td>
<td _ngcontent-c10="" class="td-fixed-width-20 no-side-padding">
<img _ngcontent-c10="" class="outputLogo" src="https://qa-server/Services/content/logos/AAAA1.png" alt="AAA1">
</td>
<td _ngcontent-c10="" class="td-text-bold">
AAA1 Output
<!---->
</td>
</tr>
<tr _ngcontent-c10="">
<td _ngcontent-c10="" class="td-fixed-width-35">
<label _ngcontent-c10="">
<input _ngcontent-c10="" type="checkbox" value="" class="ng-untouched ng-pristine ng-valid">
</label>
</td>
<td _ngcontent-c10="" class="td-fixed-width-20 no-side-padding">
<img _ngcontent-c10="" class="outputLogo" src="https://qa-server/Services/content/logos/BBB1.png" alt="BBB1">
</td>
<td _ngcontent-c10="" class="td-text-bold">
BBB1 Output
<!---->
</td>
</tr>
<tr _ngcontent-c10="">
<td _ngcontent-c10="" class="td-fixed-width-35">
<label _ngcontent-c10="">
<input _ngcontent-c10="" type="checkbox" value="" class="ng-untouched ng-pristine ng-valid">
</label>
</td>
<td _ngcontent-c10="" class="td-fixed-width-20 no-side-padding">
<img _ngcontent-c10="" class="outputLogo" src="https://qa-server/Services/content/logos/CCC1.png" alt="CCC1">
</td>
<td _ngcontent-c10="" class="td-text-bold">
CCC1 Output
<!---->
</td>
</tr>
我正在尝试在列表中找到第一行以单击复选框,这些是我已经尝试过的:
webElement = Driver.FindElement(By.XPath("//*[contains(text(),'AAA1 Output')]//preceding::label/input[@class='ng-untouched ng-pristine ng-valid'][@type='checkbox']"));
webElement = Driver.FindElement(By.XPath("//*[.,'AAA1 Output')]//preceding::label/input[@class='ng-untouched ng-pristine ng-valid'][@type='checkbox']"));
webElement = Driver.FindElement(By.XPath("//*[contains(text(),'AAA1 Output')]//preceding::input[@class='ng-untouched ng-pristine ng-valid'][@type='checkbox']"));
webElement = Driver.FindElement(By.XPath("//*[.,'AAA1 Output')]//preceding::input[@class='ng-untouched ng-pristine ng-valid'][@type='checkbox']"));
webElement = Driver.Instance.FindElement(By.XPath("//div[@class='panel panel-info']//following::tr[contains(., 'AAA1 Output')]/td[1]"));
webElement = Driver.Instance.FindElement(By.XPath("//[contains(.,'ABC Output']//following::tr[contains(., 'AAA1 Output')]/td[1]"));
但是,他们不能点击第一个元素的复选框。
【问题讨论】:
-
[1][1] 也许这两个主题可能会有所帮助How take XPATH inside a iframe? & Selenium Unable to locate element (Python) WebScraping
-
这个是复选框,-w3 Tutorial Page,这个是 DOM,-
document.getElementById("myCheck").checked = true; -
您能否使用
HTML更新问题,包括<iframe>标签和您处理switching to the iframe的代码块?