Web Page I am testing has a scroll web element. Elements that can be viewed will change when we scroll to certain points. In back end, script can detect 50 elements where as 20 elements are view-able to perform click operations.
There are around 200 elements in the application, out of which 15 displayed to perform any actions, 50 are detected in back ground. elements detected will change when we scroll.
I am trying to scroll by using
((JavascriptExecutor) driver).executeScript("document.querySelector('#availableElements_scrollOutter').scroll(0, 1000)");
once it scrolled to that point, I need to click on one of the 15 elements (in back ground, selenium script can detect 50 elements) that are viewed in that window
//To scroll
((JavascriptExecutor) driver).executeScript("document.querySelector('#availableETypes_scrollOutter').scroll(0, 1000)");
//Finding all elements present
//this will detect 50 rows
List<WebElement> elements=driver.findElements(By.xpath("//*[@id='availableETypes_itemsHolder']/*[contains(@id, 'availableETypes_i')]/div"));
//Getting 4th row
ExpectedConditions allVisibleElements1 = (ExpectedConditions) ExpectedConditions.visibilityOfAllElements(elements);
List<WebElement> allVisibleElements=(List<WebElement>) allVisibleElements1;
WebElement row= allVisibleElements.get(4);
//click on 4th child of that row
row.findElement(By.xpath("./div[4]/div")).click();
This code is throwing errors like
org.openqa.selenium.support.ui.ExpectedConditions$9 cannot be cast to org.openqa.selenium.support.ui.ExpectedConditions
ElementNotClikable
and some other which differ every time I run code.
Will works fine in debug mode.
Below is the table on the webpage I am working on. I need to scroll down to x point and click on the n'th arrow mark.
As far as I understood from the description we want to Scroll to a certain point and then get all the elements present with this xpath locator (//[@id='availableETypes_itemsHolder']/[contains(@id, 'availableETypes_i')]/div) and finally click on nth element.
Reason you are getting element not clickable error is because the 4th Element you are trying to click is probably not the 4th element you see after scrolling but the 4th element from top which is not currently in view.
Please let me know if below piece of code works as per your expectations:
((JavascriptExecutor) driver).executeScript("document.querySelector('#availableETypes_scrollOutter').scroll(0, 1000)");
List<WebElement> elements=wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id='availableETypes_itemsHolder']/*[contains(@id,'availableETypes_i')]/div")));
//Action Class to Move to Element not in Frame
Actions action = new Actions(driver);
//Move to 4th Row then move to 4th Row's Arrow and then Click
action.moveToElement(elements.get(4)).moveToElement(driver.findElement(By.xpath("./div[4]/div"))).click().build().perform();
I would suggest you to keep the arrow locator path dynamic as well.