这是在 FF 浏览器上。 我有一个网络应用程序,工具栏上有一个下一步按钮。我的 Selenium 脚本找到了该按钮,并在该元素突出显示时单击了它,但下一页未打开。
如何才能转到下一页?
这是处于空闲状态的工具栏的图像:
点击元素后:
正如另一篇文章中所建议的,我单击不可单击的元素来获得焦点,然后单击下一个按钮...但该按钮突出显示但不会转到下一页
driver.findElement(By.xpath("/html/body/form/span[1]/div/table/tbody/tr[4]/td/span")).click();
driver.findElement(By.xpath("/html/body/form/span[1]/div/table/tbody/tr[4]/td/span/div/div/div[1]/table/tbody/tr/td[11]/div")).click();
HTML 的一部分是
<table id="ReportViewer1_fixedTable" cellspacing="0" cellpadding="0" style="table-layout:fixed;width:100%;height:100%;">
<tbody>
<tr style="background-color:#ECE9D8;">
<tr id="ParametersRowReportViewer1" style="display:none;">
<tr style="height:6px;font-size:2pt;display:none;">
<tr>
<td colspan="3">
<span id="ReportViewer1_Toolbar">
<div id="ReportViewer1_ctl06" style="font-family:Verdana;font-size:8pt;border-bottom:1px #CCCCCC Solid;background-color:#ECE9D8;background-image:url(/PlateTechManager/Reserved.ReportViewerWebControl.axd?OpType=BackImage&Version=10.0.30319.1&Color=%23ECE9D8&Name=Microsoft.Reporting.WebForms.Icons.toolbar_bk.png);">
<div style="padding-left:6px;">
<div class=" " style="display:inline-block;font-family:Verdana;font-size:8pt;vertical-align:top;">
<table cellspacing="0" cellpadding="0" style="display:inline;">
<tbody>
<tr>
<td height="28px">
<td width="4px"></td>
<td height="28px">
<td width="4px"></td>
<td height="28px">
<td width="4px"></td>
<td height="28px">
<td width="4px"></td>
<td height="28px">
<td width="4px"></td>
<td height="28px">
<div id="ReportViewer1_ctl06_ctl00_Next">
<div id="ReportViewer1_ctl06_ctl00_Next_ctl00" style="border: 1px solid transparent; background-color: transparent; cursor: default;">
<table title="Next Page">
<tbody>
<tr>
<td>
我尝试了这个,但没有成功
Actions builder = new Actions(driver);
WebElement we = driver.findElement(By.xpath("/html/body/form/span[1]/div/table/tbody/tr[4]/td/span/div/div/div[1]/table/tbody/tr/td[11]/div"));
builder.moveToElement(we).click().build().perform();
编辑 在进一步研究此行为后,似乎该元素被突出显示,但实际上并未被单击。(我怎么知道这一点?当测试结束时,该元素保持突出显示。只要我移动鼠标,该元素就会变得正常)所以不要不知道为什么点击没有发生
最佳答案
要尝试两件事:
移动到某个元素并单击:
Actions builder = new Actions(driver); builder.moveToElement(link).click(link).build().perform();
通过执行 javascript
click()
单击链接:((JavascriptExecutor) driver).executeScript("arguments[0].click();", link);
其中 link
是链接的 WebElement
实例(findElement()
调用的结果)。
关于java - Selenium 找到 Web 应用程序的 "next"按钮,但 click() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29213571/