[英]Uploading files using Selenium in C#?
我试图单击按钮,使用XPath通过Selenium上传完成的表单,但这对它的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>
下面是我传入XPath的NUnit类
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();
}
鉴于您提供的HTML上下文有限,我将在XPath中使用contains
来搜索包含字符串"Upload completed form"
给定button
元素。
//button[contains(., 'Upload completed form')]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.