how handle auto suggest in “from” and “destination” box for this website “https://www.goibibo.com/” in selenium

后端 未结 3 1772
感动是毒
感动是毒 2020-12-22 08:12

how handle auto suggest in \"from\" and \"destination\" box for this website \"https://www.goibibo.com/\" in selenium. please help

I tired using the basic method bu

3条回答
  •  梦毁少年i
    2020-12-22 08:53

    So you can try one solution please find the below screenshot,

    As you can see in screenshot if i type M in text box then dropdown shows the record respect to letter 'M' and if you see in source the

      which is dynamic as you see just below so you need to handle that dropdown by it's locator it is dynamic hence first you need to pass some text in text box and after that you need to select the element from the drop down using Select in selenium you use selectByVisibleText("") or what ever or you can use List you can store all the respected sources (Mumbai, Mysore ,etc)coming from dropdown and use it wisely

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gosuggest_inputSrc']))).sendKeys("M");
      List myList = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("Xpath of the dynamic drop down")));
      for (WebElement element:myList) {
               if(element.getText().contains("Mumbai"));
               element.click();
          }
      

      i gave you an idea let me know if you need any further help

提交回复
热议问题