How to check if refresh page event occurs or not after an UI event (ex. click on a button)

后端 未结 1 564
生来不讨喜
生来不讨喜 2021-01-26 09:10

Got the following code:

 driver.findElement(By.id(\"input_search\")).click();
 driver.findElement(By.id(\"input_search\")).clear();
 if(lower3 == true){
    //re         


        
相关标签:
1条回答
  • 2021-01-26 10:09

    You can use any of these to solve your purpose:

    Solution 1: Verify an element after search action performed.

    driver.findElement(By.id("input_search")).clear();
    driver.findElement(By.id("input_search")).click();
    
    //here write code to wait for an element available on search result page
    
    try{
    if(driver.findElement(By.id("search result page element")).isDisplayed() == true){
    System.out.println("Search successful");
    } catch (NoSuchElementFound ee){System.out.println("Search not successful");}
    

    Solution 2: Check for page loaded or not after search action performed using java script.

    driver.findElement(By.id("input_search")).clear();
    driver.findElement(By.id("input_search")).click();
    
    //here write code to wait for sometime around 10-20 seconds
    
    JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
    String s = (String) jsExecutor.executeScript("var s1 = 'Search successful'; var s2 = 'Search not successful'; if(document.readyState === 'complete'){return s1;} else {return s2;}");
    

    Both the code snippet is tested for Google.

    0 讨论(0)
提交回复
热议问题