我正在尝试自动填充Web应用程序中的时间表。为此,我有一个等待提交的周末列表,如图像:
现在需要用户输入以选择这些周末中的任何一个,并根据用户输入,网页驱动程序将点击选定的周末。相同的代码在Firefox中工作正常,但对于chrome,我收到此错误
这是我执行此任务的代码:
ArrayList<WebElement> list1=(ArrayList<WebElement>) driver.findElements(By.tagName("a"));
//System.out.println(list1.size());
int count=0;
System.out.println("*****************************************************************");
for(WebElement i : list1) {
if ("submissionPeriod".equals(i.getAttribute("id"))){
count+=1;
System.out.println(count+":"+(i.getText()));
}
}
System.out.println("*****************************************************************");
if(count==0)
System.out.println("there is no pending submission");
else{
System.out.println("Select one out of these Above Pending Time Sheets for submit or save data automatically....");
int input1=isr.nextInt();
String ele="//div["+input1+"]"+"[@id='PendingSubmission']";
// System.out.println(ele);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(ele)));
driver.findElement(By.xpath(ele)).click();
答案 0 :(得分:1)
你可以使用java脚本来完成它。
JavascriptExecuter js = (JavascriptExecuter)driver;
js.executeScript("arguments[0].click()", <your web element>);
答案 1 :(得分:1)
您可以继续使用JavascriptExecutor
WebElement ele = driver.findElement(By.xpath("//div[@id='PendingSubmission']["+input1+"]"));
JavascriptExecuter js = (JavascriptExecuter)driver;
js.executeScript("arguments[0].click()", ele);
答案 2 :(得分:0)
问题似乎与xpath一样,因为你在其中使用位置。在大多数情况下,使用位置并不可取。
我建议去索引,而不是在xpath中使用位置。
String ele="(//div[@id='PendingSubmission'])["+input1+"]";
答案 3 :(得分:0)
这是firefox驱动程序的一个已知问题。 Click Issue.
尝试使用此解决方法。
WebElement elementtobeClicked = driver.findElement(By.xpath(ele));
//Option 1
Actions actionDriver = new Actions(driver);
actionDriver.moveToElement(elementtobeClicked).click().perform();
//Option2
JavascriptExecutor jsDriver = (JavascriptExecutor) driver;
jsDriver.executeScript("arguments[0].click();",elementtobeClicked);