1

I am new to Selenium and I have the following situation.

My html:

<div class="activeThumbnail thumbnail simple animated zoomIn" data-url="/report/sales-vs-price" style="height: 332px;">
    <div class="caption">
        <p class="thumbReportTitle">
           <a href="/report/sales-vs-price">Sales vs Price</a>
        </p>                        
    </div>
</div>

I need to simulate a click in the link so it opens the report page. I tried a couple of different options based on different responses (trying to access the link or the text):

1. This throws an exception of "element not visible"

driver.FindElementByCssSelector("a[href*='sales-vs-price']").Click();


2. Here I tried to fix the "not visible" exception so now it doesn't throw an error but it also doesn't do anything:

Actions builder = new Actions(driver);
Actions click = builder.MoveToElement(driver.FindElementByCssSelector("a[href*='sales-vs-price']")).Click();
click.Build().Perform();

or

Actions builder = new Actions(driver);
Actions click = builder.MoveToElement(driver.FindElementByXPath("//*[contains(text(),'Sales vs Price')]")).Click();
click.Build().Perform();


3. This throws an expception of "Unable to locate element"

driver.FindElementByPartialLinkText("a[href='sales-vs-price']").Click();


4. Or this, with the exception: "element not visible":

driver.FindElementByXPath("//*[contains(text(),'Sales vs Price')]").Click();

I am not sure what I am doing wrong... Does any one know if I can access data-url? Or does someone have any other ideas?

Thanks!

Sibele Lima
  • 206
  • 1
  • 3
  • 15

1 Answers1

1

Can u try this.

driver.FindElement(By.PartialLinkText("Sales vs Price")).click();

if element not found exception is thrown on using above command. use implicit wait(to ensure page is loaded fully).

if no action is performed on above command.use

driver.FindElement(By.PartialLinkText("Sales vs Price")).sendKeys(Keys.Control);
driver.FindElement(By.PartialLinkText("Sales vs Price")).click();

Keys.Control will bring focus to desired element. I faced similar issues with IE driver.

Akhil K
  • 101
  • 3