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!

asked Dec 10, 2015 at 0:41
1

1 Answer 1

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.

answered Dec 10, 2015 at 6:28

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.