【发布时间】:2018-03-31 13:28:46
【问题描述】:
我正在尝试单击按钮上传完成的表单,通过 selenium 使用 XPath,但是这对其 XPath 没有任何作用,我想知道是否有人有任何建议的答案?
以下是检查 Chrome 的 HTML。
<button ng-if="$root.AccessLevel.Standard" class="btn btn--small btn--icon ng-pristine ng-valid ng-touched" ng-model="vm.uploads[workCategory.Id].reference" ngf-max-size="'5MB'" ngf-model-invalid="vm.uploads[workCategory.Id].referenceInvalid" ngf-pattern="'.pdf,.doc,.docx,.bmp,.gif,.jpg,.jpeg,.tif,.wmf,.png'" ngf-select="vm.uploadFile($file, 'WorkCategoryReference', workCategory.Id, workCategory.References, workCategory.Id+'uploadRef')">
<span promise="vm.promises[workCategory.Id+'uploadRef']">
<span ng-hide="pending" class="">
<i class="fa fa-lg fa-cloud-upload"></i>
</span>
<span ng-show="pending" class="ng-hide">
<i class="fa fa-lg fa-refresh fa-spin"></i>
</span>
</span>
Upload completed form
</button>
下面是我的 NUnit 类,其中传入了 XPath
wait.PathWaitAndClick(driver, "*[@id=\"accordiongroup - 299 - 4516 - panel\"]/div/div[2]/div[1]/table/tfoot/tr/td/button", 2000);
下面我也在使用 WebExtension 方法。
public static void PathWaitAndClick(this WebDriverWait wait, IWebDriver driver, string path, int pause = 0)
{
if (pause > 0)
{
System.Threading.Thread.Sleep(pause);
}
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(path)));
IWebElement viewAllWc = driver.FindElement(By.XPath(path));
if (pause > 0)
{
System.Threading.Thread.Sleep(pause);
}
viewAllWc.Click();
}
【问题讨论】:
-
三个简单的问题:你的xpath在点击的那一刻有效吗?按钮是否在 iframe 标签内?你能暂停你的运行方法并检查浏览器控制台是否抛出了一些错误吗?
-
它没有,达到我的断点@StriterAlfa
-
您可以在 chrome 控制台上使用命令 $x("your xpath") 检查您的 xpath 是否有效。您还可以检查它是否在检查页面 html 的 iframe 内。如果调试器无法到达您的断点来调试您的单击操作,则说明有问题不是您寻求帮助的原因
-
@StriterAlfa 我得到的错误是 wait.PathWaitAndClick(driver, "*[@id=\"accordiongroup-299-451-panel\"]/div/div[2]/div[1 ]/table/tfoot/tr/td/button", 2000) 函数评估被禁用,因为之前的函数评估超时。您必须继续执行才能重新启用函数评估。无效
-
我知道错误出现在该行,但是您是否按照我所说的测试了 xpath?您是否检查过该元素是否在 iframe 内?浏览器控制台有错误?所有这些点都会影响并导致该行出现错误。