2

HTML code:

<a ng-repeat="group in groups()" ng-href="phones/Apple/iPhone%203G%20or%203GS/" class="ng-scope" href="phones/Apple/iPhone%203G%20or%203GS/">
        <div class="card-box device-box">
            <span class="card-text ng-binding">iPhone 3G or 3GS</span>
            <i class="fa fa-chevron-right visible-xs"></i>
            <div class="clearfix"></div>
        </div>
    </a>

C# code:

driver.FindElement(By.LinkText("IPHONE 3G 16GB")).Click();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Blanc
  • 21
  • 2
  • So you provided the HTML and the code but didn't state what the problem is. I'm assuming that code doesn't work... what's the result? Please provide more details. – JeffC Sep 25 '15 at 18:24
  • Will By.LinkText work? The tag you are referencing is not an A tag (link). – JeffC Sep 25 '15 at 18:25

2 Answers2

1

I would make an XPath expression here to find the a element that has a span element inside having iPhone 3G or 3GS text:

driver.FindElement(By.XPath("//a[div/span = 'iPhone 3G or 3GS']")).Click();

You may also try approaching it with PartialLinkText locator instead:

driver.FindElement(By.PartialLinkText("IPHONE 3G 16GB")).Click();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • @Blanc nice, what do you mean by "does not work"? Any errors? – alecxe Sep 25 '15 at 20:37
  • I also recommend finding the element by XPath. Getting the path right isn't always the most straightforward, but there are some handy features in Chrome and FireFox (plugins as well) that will let you get an element's XPath which you can then use in your code. – Tyler Sep 25 '15 at 20:42
  • @alecxe.: I am getting element not found when I use driver.FindElement(By.XPath("//a[div/span = 'iPhone 3G or 3GS']")).Click(); – Blanc Sep 25 '15 at 22:51
0

Try with below xpath

By.XPath("//a//span[text()='iPhone 3G or 3GS']")
Santoshsarma
  • 5,627
  • 1
  • 24
  • 39