简体   繁体   English

带有IE 9的Selenium Webdriver-没有这样的元素

[英]Selenium Webdriver with IE 9 - No Such Element

Im automating an external product where I dont have access to source code. 我将无法访问源代码的外部产品自动化。

this is the view source code 这是查看源代码

<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>

I want to click the last hyperlink after page load.Landing page has sso authentication, so i added implicit wait for 20 seconds after page load. 我想在页面加载后单击最后一个超链接。登陆页面具有sso身份验证,因此我在页面加载后添加了20秒的隐式等待。

java code Java代码

driver = (WebDriver) new InternetExplorerDriver(capab1);
driver.get("url");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//a[@href = 'CreateUserDocument.aspx?code=Presentation_PDF_RES_Mtg']")).click();

I use Selenium 2.44 library with 2.32 IEDriverServer.exe in 32 bit IE 9 browser. 我在32位IE 9浏览器中将Selenium 2.44库与2.32 IEDriverServer.exe一起使用。

Any thoughts are appreciated.Thanks ! 任何想法都表示赞赏。谢谢!

From what I can see, it's a Carousel Slider . 据我所知 ,这是一个Carousel Slider So, probably you have to wait till the item comes up. 因此,可能您必须等到项目出现。 Try the below code and see if it works: 尝试下面的代码,看看是否有效:

    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());
    }

Before that switch to iframe using the below code: 在此之前,请使用以下代码切换到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());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM