@Florent B.回答我的问题在问候上传一个文档,其中的元素不是一个输入类型="文件" 在这里
现在,我有另一个文档上传部分,我无法正确处理.屏幕上有一个带有输入类型="提交"按钮的覆盖图,所以我使用上面超链接的解决方案,它确实上传了文档,但是,它没有改变显示文件被上传的状态,这是必需的实际完成订单.
这是我当前获取文档的代码,它只是没有在对话框中反映出来:
// disable the click event on an `<input>` file
((JavascriptExecutor)getDriver()).executeScript(
"HTMLInputElement.prototype.click = function() { " +
" if(this.type !== 'file') HTMLElement.prototype.click.call(this); " +
"}; " );
// trigger the upload
VOrderDetails.uploadReport_btn(getDriver()).click();
// change the visibility of the file input control
WebElement elem = getDriver().findElement(By.id("UploadLib_Uploader_js"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) getDriver()).executeScript(js, elem);
Thread.sleep(1000);
getDriver().findElement(By.cssSelector("input[type=file]"))
.sendKeys(filePath);
Run Code Online (Sandbox Code Playgroud)
手动上载文档时,文档显示如下,显示上载了测试PDF.pdf文件并允许您完成订单:
有没有办法"伪造"它以显示已在此叠加层上载的文件?
这是这篇文章的HTML:
<div id="divSetComplete" style="width: 594px; display: block; top: 316.5px;" class="MessageBox HideOldProgressBar">
<div class="DialogTitle">Complete assignment</div>
<div id="divSetCompleteFields" class="DialogSection dsBorder …Run Code Online (Sandbox Code Playgroud) 我需要使用Chromedriver通过Selenium WebDriver上传文档.我已经尝试了所有的Action类和Javascript的东西,但那些不起作用.我假设它们不起作用,因为那些依赖于按钮作为输入字段,但是,我正在处理的上传按钮不是.它的HTML看起来像这样:
<a id="Dialogs_Dialogs_lbAttachUpload" onclick="return ButtonVerifyEnabled(this, ShowFileSelect);" class="SkinButton sbBlue" onmouseover="ButtonHover(this,30);" onmouseout="ButtonLeave(this);" onmousedown="ButtonDown(this,30);" onmouseup="ButtonHover(this,30);" skinheight="30" style="color: white; width: 132px; height: 30px; line-height: 30px; background-position: 0px 0px;" title=""><div class="SkinButtonLeft" style="background-position: 0px 0px;"></div><div class="SkinButtonRight" style="background-position: -4px 0px;"></div>Upload documents</a>
Run Code Online (Sandbox Code Playgroud)
我有AutoIT和Sikuli实现和工作,但这些解决方案的问题是我通过Jenkins运行Selenium测试时无法让它们工作.
我最近的尝试看起来像这样:
WebElement upload = SConfirmOrder.uploadDocuments_btn(driver);
Actions actions = new Actions(driver);
actions.moveToElement(upload);
actions.sendKeys("filepath\\Test PDF.pdf");
Run Code Online (Sandbox Code Playgroud)
它成功运行,但实际上没有文档上传.
如果在@BeforeSuite注释中满足条件,是否有办法退出整个测试套件?也许是一种调用@AfterSuite并绕过整个测试的方法?
我在@BeforeSuite中进行数据库调用.如果查询返回任何结果,我发送一封电子邮件,现在我想要杀死整个测试套件.
我曾尝试System.exit(1);和org.testng.Assert.fail("There are unpaid invoices");,但那些都终止整个套件.我的脚本设置为并行运行类,当我从test.xml文件运行测试时,每个类都尝试启动并打开一个窗口,然后立即关闭它.
仅供参考,在@BeforeClass或@BeforeMethod之前不会创建驱动程序(取决于我为并行方法或类创建的开关).所以在所有现实中,甚至都不应该尝试打开浏览器窗口.
使用JMeter,我试图从整个HTML响应页面获取特定值并将其存储为变量.问题是我需要提取的值是HTML代码的第3行,标识符在第1行.
<td><span class="outputLabel1">Total</span></td>
<td><span class="outputText"></span></td>
<td width="15%" style="text-align: right;"><span class="outputText">1,068.00</span></td>
我需要从最后一行中提取"1,068.00",但仍需要匹配第一行的"Total".