0

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.

java code

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.

Any thoughts are appreciated.Thanks !

mirra
  • 1
  • 2

1 Answers1

0

From what I can see, it's a 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:

 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());
    }
Subh
  • 4,354
  • 1
  • 13
  • 32
  • I tried the same, still I get nosuchelement.I dont have access to source code, So I inspected the dom version of source. – mirra Dec 04 '14 at 16:58
  • Here is the snippet
    – mirra Dec 04 '14 at 16:59
  • i see div is embedded inside iframe.So do I need to swtich to iframe before accessing the div – mirra Dec 04 '14 at 17:00
  • Yes. Then, you've to switch to frame first before executing the code above. I have added the relevant code snippet for switching to frame above. Please check. Also, after the task with the frame is over, you can switch back to the main window using the code `driver.switchTo.defaultContent();` – Subh Dec 04 '14 at 17:07
  • Now I get - Exception in thread "main" org.openqa.selenium.NoSuchFrameException: No frame found. Is it beacuse it is trying to look for frame name.But I have only id. – mirra Dec 04 '14 at 18:09
  • It's fine. You can switch to a frame using id also. See this link for different ways to switch to a frame: [http://stackoverflow.com/a/20181195/4193730](http://stackoverflow.com/a/20181195/4193730). Also, I have updated the code above for waiting till 30 seconds till the iframe is available and then switching to it. See if that works. – Subh Dec 05 '14 at 06:19