代码之家  ›  专栏  ›  技术社区  ›  Shi Tim

当父< UL>元素通过Java硒包含属性样式=“显示:否”时,如何创建AutoTebug < LI>元素的列表

  •  0
  • Shi Tim  · 技术社区  · 6 年前
    < >我使用Java硒来创建自动化项目。现在在我们的Web应用程序中,有地址输入框,并具有自动完成功能。问题是输入部分地址后,我们需要单击列表中的某个选项。这是HTML:

    现在我试着去拿名单。但失败:

    webelement autocompelet=driver.findelement(by.xpath(”/html/body/ul[1]“);
    list<webelement>选项=autocompolet.findelements(by.tagname(“li”));
    logger.debug(options.size());
    
    
    hrml ul list

    WebElement autoCompelet = driver.findElement(By.xpath("/html/body/ul[1]"));
    List<WebElement> options = autoCompelet.findElements(By.tagName("li"));
    logger.debug(options.size());
    for (WebElement option1 : options) {
        logger.debug(option1);
    }
    

  • WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/ul[1]/li[1]")));
    

  • 5 回复  |  直到 6 年前
        1
  •  0
  •   flyingfox    6 年前

    By.className("li") By.Name("li")

    ul li

    WebElement autoCompelet = driver.findElement(By.xpath("//ul[@class='af_list']"));
    List<WebElement> options = autoCompelet.findElements(By.Name("li"));
    logger.debug(options.size());
    for (WebElement option1 : options) {
        logger.debug(option1);
    }
    
        2
  •  0
  •   Subburaj    6 年前

        //wait is added in order to check the presence of autocomplete suggestion 
        WebDriverWait wait=new WebDriverWait(driver,20);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("af_list")));
    
        List<WebElement> options = driver.findElements(By.xpath("//ul[@class='af_list']/li"));
        logger.debug(options.size());
        for (WebElement option1 : options) {
            logger.debug(option1.getText());
        }
    

    af_list

        3
  •  0
  •   cruisepandey    6 年前

    <li> getText()

    List<WebElement> options = driver.findElements(By.cssSelector("ul.af_list li"));
     System.out.println(options.size());
     logger.debug(options.size());
     for(WebElement options1 : options)
      {
        logger.debug(options1.getText());
       }
    

    <

        4
  •  0
  •   undetected Selenium    6 年前

    <li> <ul> <

    WebElement autoCompelet = driver.findElement(By.xpath("//ul[@class='af_list']"));
    ((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('style')", autoCompelet);
    List<WebElement> options = autoCompelet.findElements(By.xpath("./li[@class='af_item']"));
    for (WebElement option1 : options) {
        System.out.println(option1.getText());
    }
    
        5
  •  0
  •   cruisepandey    6 年前

    sendKeys() Keys.DOWN Keys.ENTER 文本的一部分,其他部分在下面开始填充,所以您基本上在某种程度上键入,直到填充中的第一个选项 下拉列表 文本就是你想要的。然后做 sendKeys(Keys.DOWN) 然后 sendKeys(Keys.ENTER)