0

我正在尝试单击 python 中的 java 脚本组合框,但是如果我正常执行此操作,它会给我一个错误,说组合框已隐藏,我以编程方式等待组合框出现但它没有出现。组合框中的这个选项是一个子菜单,但是,如果我只从真实菜单中选择一个选项,它可以工作,但不能与子菜单选项一起使用。这是网站,https: //mbsdisclosure.fanniemae.com/PoolTalk2/index.html > Advanced Search > #then the combo box I am looking for the sub menu option for Preliminary Mega > Preliminary Mega: Fannie Mae/Ginnie Mae支持可调利率。谢谢!

4

1 回答 1

0

Selenium won't be able to click as element you want to select is considered to be invisible(inactive). So the only way(imho) to use js to resolve this issue. That worked for me in java:

 @Test
    public void neeededDropdownSelect() throws InterruptedException {
        driver.get("https://mbsdisclosure.fanniemae.com/PoolTalk2/index.html");
          jsClickOnElement("li#tab_1>a>span");
        WebElement dropdownMenu = fluentWait(By.cssSelector("span#asSelectedSecType"));
        dropdownMenu.click();


        jsClickOnElement("div[class=\"fg-menu-container ui-widget ui-widget-content ui-corner-all fg-menu-flyout\"] ul[class=\"fg-menu ui-corner-all\"]>li>a[id=\"MEGA_INTERIM\"]");
        jsClickOnElement("div[class=\"fg-menu-container ui-widget ui-widget-content ui-corner-all fg-menu-flyout\"] ul[class=\"fg-menu ui-corner-all\"]>li>ul.ui-corner-all a[id=\"MEGA_INTERIM_ARM\"]");

    }

  public WebElement fluentWait(final By locator){
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(30, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

        WebElement foo = wait.until(
                new Function<WebDriver, WebElement>() {
                    public WebElement apply(WebDriver driver) {
                        return driver.findElement(locator);
                    }
                }
        );
        return  foo;              }     ;

    public void jsClickOnElement(String cssSel){
        JavascriptExecutor js = (JavascriptExecutor) driver;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("var x = $(\'"+cssSel+"\');");
        stringBuilder.append("x.click();");
        js.executeScript(stringBuilder.toString());

    }

Hope this helps you)

于 2012-09-12T00:19:30.970 回答