Reputation: 53
I am trying to automate filling of time sheet in a Web application. For that I have a list of weekend for pending submission like in image:
And now It take input from the user to select anyone of these weekend and according to user input, web driver will click on selected weekend. Same code is working fine in Firefox but for chrome , I am getting this error
And this is my code for this task:
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();
Upvotes: 0
Views: 2606
Reputation: 3235
You can go ahead with JavascriptExecutor
WebElement ele = driver.findElement(By.xpath("//div[@id='PendingSubmission']["+input1+"]"));
JavascriptExecuter js = (JavascriptExecuter)driver;
js.executeScript("arguments[0].click()", ele);
Upvotes: 1
Reputation: 439
you can do it by using java script.
JavascriptExecuter js = (JavascriptExecuter)driver;
js.executeScript("arguments[0].click()", <your web element>);
Upvotes: 1
Reputation: 89
It's a known issue with firefox driver. Click Issue.
Try this workaround methods.
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);
Upvotes: 0
Reputation: 1074
Issue seems with the xpath, as you are using position in it. Using position is not preferable in most of the cases.
Instead of using position in xpath, I would advise to go for index.
String ele="(//div[@id='PendingSubmission'])["+input1+"]";
Upvotes: 0