0

Im in a situation that the window that asks me to choose a wizard to proceed with my project is not appearing on a Button Click. It clicks the button successfully but i dont see the window. Referred to multiple blogs that didnt help me to resolve this issue.

Below is the HTML snippet of that window

<div data-reactroot="" class="backdrop custom-modal-dialog"><div class="wizard-selection-modal-dialog-box"><div class="header-container"><h1 class="flex-grow">Wizard Window</h1><div class="icon icon-close close"></div></div><div class="warning-box"><div class="icon icon-info-circle"></div><div class="info-text">Please choose the assess type you want to proceed</div></div><div class="selection-container"><div class="selection-box selected"><h1>Standard Assess</h1><div class="facts-container"><div class="fact-block"><div class="icon icon-check"></div><div class="fact-text">Instruction1</div></div><div class="fact-block"><div class="icon icon-check"></div><div class="fact-text">Instruction2</div></div><div class="fact-block"><div class="icon icon-check"></div><div class="fact-text">Instruction3</div></div></div><div class="selection-indicator"><div class="icon icon-check"></div></div></div><div class="selection-box"><h1>Group Assess</h1><div class="facts-container"><div class="fact-block"><div class="icon icon-check"></div><div class="fact-text">Instruction1</div></div><div class="fact-block"><div class="icon icon-check"></div><div class="fact-text">Instruction2</div></div><div class="fact-block"><div class="icon icon-check"></div><div class="fact-text">Instruction3</div></div></div><div class="selection-indicator"></div></div></div><div class="footer-container"><div class="continue-container"><div class="continue-text">Continue Assess</div><div class="icon icon-sent-offers"></div></div></div></div>

Below is the HTML script of the button that I click to open the wizard window,

<div class="offer-item" id="offer-item-0069E000005uD7PQAU"><div class="opportunity-item"><div class="offer-column"><div class="offer-name no-contracts"><!-- react-text: 135 -->Optimum Wartung256<!-- /react-text --><div class="offline-offer icon icon-offline hidden"><div class="last-sync-started"></div></div></div><div class="opportunity-filters"><div class="opportunity-filter">Omförhandling</div></div></div><div class="building-column"><div class="building-equipment-info"><div class="buildings"><span class="icon icon-building"></span><span class="count">0</span></div></div></div><div class="opportunity-status-column"><div class="opportunity-close-date">26.9.2017</div><div class="opportunity-status">Starta bedömningen</div></div></div></div>

Below is the code that I used,

  public void BeginAssessWizardWindow(String opportunityStr) {
          try {
    List<WebElement> opportunities = driver.findElements(By.xpath("//a[@class='offer-item']"));
    for (WebElement opportunite : opportunities) {
      WebElement OpportunityName = opportunite.findElement(By.cssSelector("div.offer-name.no-contracts"));
      String textval = OpportunityName.getText();
      if (textval.equalsIgnoreCase(opportunityStr)) {
        //WebElement BeginAssessButton =opportunite.findElement(By.cssSelector("div.opportunity-status"));
//WebDriverWait wait = new WebDriverWait(driver, 100);

//wait.until(ExpectedConditions.visibilityOfElementLocated (By.cssSelector ("div.opportunity-status")));
        //WaitAndClickElementDirectly(BeginAssessButton);
        JavascriptExecutor executor = (JavascriptExecutor)driver;
        executor.executeScript("document.getElementByClass('opportunity-status').click();");
        //Thread.sleep(1000);
        //checkPageIsReady();
        //FluentWaitClick(BeginAssessButton);
        logger.info("Entered into Begin Assess function" + textval);
        break;
      } 
    }
    //Thread.sleep(1000);
    CheckAssessmentWizardWindow();
  }
  catch(Exception e)
  {
        Assert.fail("Couldn't proceed with Assessments" + e);
      //CheckAssessmentWizardWindow();
  }
  }

public void CheckAssessmentWizardWindow()
{
    try {
          //checkPageIsReady();
          WebElement WizardWindow = FindTheElement("cssSelector",AssessmentPageData.AssessmentWizard);

  WaitTillClickable("cssSelector",AssessmentPageData.AssessmentWizard);
            if(WizardWindow.isDisplayed())
            {

 //WaitTillElementVisible("xpath",AssessmentPageData.AssessmentWizard);

WaitAndClickOnElement("xpath",AssessmentPageData.AssessmentOption);

WaitTillElementVisible("xpath",AssessmentPageData.AssessmentPage);
             ClickOnElement("xpath",AssessmentPageData.AssessmentPage);
            }
            else
            {                    

            }
    }
    catch(Exception e)
    {
         Assert.fail(e);
    }
}

Please suggest me some possible ways how to resolve such situation.

Code to check whether the page is ready,

  public void checkPageIsReady() {

  JavascriptExecutor js = (JavascriptExecutor)driver;


  //Initially bellow given if condition will check ready state of page.
  if (js.executeScript("return document.readyState").toString().equals("complete")){ 
   System.out.println("Page Is loaded.");
   return; 
  } 

  //This loop will rotate for 25 times to check If page Is ready after every 1 second.
  //You can replace your value with 25 If you wants to Increase or decrease wait time.
  for (int i=0; i<25; i++){ 
   try {
    Thread.sleep(1000);
    }catch (InterruptedException e) {} 
   //To check page ready state.
   if (js.executeScript("return document.readyState").toString().equals("complete")){ 
    break; 
   }   
  }
 }
Roja
  • 293
  • 1
  • 5
  • 21
  • You don't say how it's not working. Have you reviewed the JS error log, the network requests, etc.? Also, I see no ` – Paul Hicks Feb 07 '18 at 23:57
  • Thanks for your response @PaulHicks . Yes It is not actually a button. I tried verifying the page load by all possible solutions given in the link [link]https://stackoverflow.com/questions/10720325/selenium-webdriver-wait-for-complex-page-with-javascriptjs-to-load . But still the same situation. Could this be any technical reason? or Selenium is not feasible with this code? Im scared. The code that i tried is updated in the query area. – Roja Feb 08 '18 at 05:02
  • Could this be because of using 'break' in the if condition? Im breaking it once the button/element is clicked. – Roja Feb 09 '18 at 07:22
  • 1
    If opportunityStr and/or OpportunityName.getText() is not unique, then yes: the logic might be finding some other (possibly disabled) element and clicking it, which isn't doing anything. The logic in there seems to be attempting to make up for a lack of id / name attributes on elements; it is much better to uniquely identify every interesting WebElement, rather than searching through potential matches like this code is doing. – Paul Hicks Feb 09 '18 at 07:43
  • Im surprised that the if condition is not satisfied in this case even though the correct value is passed. Unsure why. Kept aside to analyse this later. I have changed the logic. There is a search option/field on the page wherein i provide this text and I directly click on the item and that provides me the solution for current situation. Thanks a lot @PaulHicks. – Roja Feb 13 '18 at 05:28

0 Answers0