1

I am making a script using selenium and at one step it shows loading icon in center of webpage.The loading icon appears after 1st line is executed

test.driver.findElement(By.id("oaapprove")).click();
test.driver.findElement(By.xpath("//*[text()='DATA EXPLORER']")).click();

image

The 2nd element is still there in DOM but its not clickable so i get error as not clickable

i tried this:

Boolean isPresent=test.driver.findElements(By.xpath("//div[@class='spinner-container']")).size() > 0;
    if(isPresent)
    {
        System.out.println("Target element found");
    }
    while(test.driver.findElements(By.xpath("//div[@class='spinner-container']")).size() > 0)
    {
        try {
            System.out.println("inside");
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    if(!(test.driver.findElements(By.xpath("//div[@class='spinner-container']")).size() > 0))
    {
        System.out.println("Target element not found");
    }

It is printing "inside" till the loading icon is visible but but after icon disappears it does not print "inside" but it waits for 7-8 secs and then executes next statements. What is the cause of waiting?

Can u please tell how to i solve this.

hello
  • 33
  • 8
  • Check [this solution](https://stackoverflow.com/questions/41632230/getting-element-is-not-clickable-exception-while-click-on-a-menu-link/41632565#41632565) – Andersson Jun 17 '17 at 06:40
  • your solution is working but it is waiting even after loading icon disappeared. – hello Jun 17 '17 at 17:07
  • That might mean that you incorrectly defined the modal with loading icon – Andersson Jun 17 '17 at 17:10
  • what is the argument 10 in that? – hello Jun 17 '17 at 17:12
  • This is the timeout. If you wait more than 10 seconds, you get timeout exception – Andersson Jun 17 '17 at 17:14
  • i updated question description do u have any hint? – hello Jun 17 '17 at 17:19
  • I don't see implementation of [ExplicitWait](http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-waits) in your code. Why you'are trying to create your own approach when it's already created and works? – Andersson Jun 17 '17 at 17:23

2 Answers2

0

try actions class if it's showing using fluentwait that element is clickable:

WebElement yourElement = test.driver.findElement(By.xpath("//*[text()='DATA EXPLORER']"));

Actions act = new  Actions(test.driver);
act.moveToElement(yourElement).click().build().perform();
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46
0

I got the solution and i used stalenessOf

new WebDriverWait(driver, 10).until(ExpectedConditions.stalenessOf(findElement(By.xpath("element_path"))));
hello
  • 33
  • 8