Reputation: 81
I have written a script for datepicker to choose dates from the calendar. The scripts are running fine in local, but when I run it through jenkins the script is getting failed.
action.moveToElement(driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/div/a/span")));//locating the element to click
action.perform();
action.click(driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/div/a/span"))); //this line is not executing
action.perform();
The script to click the element is not working. I am getting error as "Element is not currently visible and so may not be interacted with"
I have also tried driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div[1]/div/a/span")).click() by replacing action.click()
but still no use.
Upvotes: 1
Views: 2421
Reputation: 1
Clicking on an element works fine locally but not in Jenkins;
first, I was locating the web element using XPATH, and when it came to clicking I tried selenium click, actions click, js click. All were working locally But not in Jenkins.
Finally what worked for me was the combination of css selector with javascriptExecutor click. This solved my problem. Now works both locally and in Jenkins.
So try the same.
Upvotes: 0
Reputation: 5647
I have faced a similar issue and after a couple of frustrating hours, I have figured out, that im my case only one thing has worked for me - JavascriptExecutor
.
I don't know why all other attempts have failed(all of them have worked well locally). It seems like Jenkins specific issues.
Anyway you can use this code snippet:
WebElement elem = driver.findElement(By.xpath("//path/to/element"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", elem);
Note: in my case I was always able to send click
action to element, but somehow browser didn't react on this action. So element was remained unclicked without any error.
Upvotes: 1
Reputation: 155
You cannot click on the hidden element using selenium because if will throw the exception that you saw. You should either make element visible (in the way the user does so) or use javascript to click (see JavaScript executor).
Upvotes: 0