Java 带有IE 9的Selenium Webdriver-无此类元素

Java 带有IE 9的Selenium Webdriver-无此类元素,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在自动化一个我无法访问源代码的外部产品 这是查看源代码 <div class="row-fluid"> <div class="span10 offset1" id="home"> <div id="myCarousel" class="carousel slide"> <div id="myCarousel-heading">

我正在自动化一个我无法访问源代码的外部产品

这是查看源代码

<div class="row-fluid">
        <div class="span10 offset1" id="home">
                <div id="myCarousel" class="carousel slide">
                    <div id="myCarousel-heading">
                        <p> What's new </p>
                </div>
                <div class="carousel-inner">
                        <div class="item active">
                            <a href="CreateUserDocument.aspx?code=Brochure_Print_Ship_Advice">
                                <img src="Custom/Themes/Vanguard/Inserts/images/carousel/Crsl_Advice.jpg" alt="">
                        </a>
                    </div><!-- End of div.item -->

                     <div class="item">
                            <a href="CreateUserDocument.aspx?code=Invite_Print_Mail_RES_Mtg">
                                <img src="Custom/Themes/Vanguard/Inserts/images/carousel/Crsl_banner_all_green.jpg" alt="">
                        </a>
                      </div><!-- End of div.item -->

                      <div class="item">
                        <a href="CreateUserDocument.aspx?code=Presentation_PDF_RES_Mtg">
                            <img src="Custom/Themes/Vanguard/Inserts/images/carousel/Crsl_RES_Pres.jpg" alt="">
                        </a>
                      </div><!-- End of div.item -->
                        </div>
我在32位IE 9浏览器中使用Selenium 2.44库和2.32 IEDriverServer.exe


任何想法都很感激。谢谢

据我所见,这是一个旋转木马滑块。所以,也许你必须等到物品出现。请尝试以下代码,看看是否有效:

    try{
        WebDriverWait wait = new WebDriverWait(driver,40);
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@href = 'CreateUserDocument.aspx?code=Presentation_PDF_RES_Mtg']")));
        element.click();
    }catch(Throwable e){
        System.err.println("Error found while waiting for the element and clicking it: "+e.getMessage());
    }
在此之前,请使用以下代码切换到iframe:

 try{
     WebDriverWait wait = new WebDriverWait(driver,30);
     wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("widgetFrame"));
    }catch(Throwable e){
        System.err.println("Error came while waiting and switching to frame. "+e.getMessage());
    }

该元素是否隐藏在
div
中?上面的代码段是所有div的嵌套部分。是body标签后的第一个元素。如果这是一个公共站点,你能共享URL吗?我尝试了相同的方法,但仍然没有找到任何元素。我无法访问源代码,所以我检查了源代码的dom版本。下面是我看到的div嵌入在iframe中的代码片段。所以我需要在访问div之前切换到iframe吗?是的。然后,在执行上述代码之前,必须先切换到frame。我已经添加了用于切换到上述框架的相关代码段。请查收。另外,在框架任务结束后,您可以使用代码
driver.switchTo.defaultContent()切换回主窗口现在我在线程“main”org.openqa.selenium.NoSuchFrameException中得到-Exception:找不到框架。是因为它试图寻找帧名称。但我只有id。
 try{
     WebDriverWait wait = new WebDriverWait(driver,30);
     wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("widgetFrame"));
    }catch(Throwable e){
        System.err.println("Error came while waiting and switching to frame. "+e.getMessage());
    }