2

I am testing localization. I am running the same URL with other countries in my data provider.

The HTML I am looking for is:

<a class="learn-more linkable" data-url="/speakers/minijambox">En savoir plus</a>

Here is my code:

String storeXpath2="//a[contains(@href,'"+url2+"')]";
driver.findElement(By.xpath(storeXpath2)).click();
System.out.println("Learn more link of Mini");

url I am trying to execute: /speakers/minijambox

Error I am getting unable to find xpath, element or method.

5
  • 1
    Can you provide a Stack trace of errors being thrown? Also, the html snippet of the <a> tag you are trying to access might help too Commented Dec 11, 2013 at 0:31
  • stack Trace : openid.stackexchange.com/affiliate/…
    – jbyogi
    Commented Dec 11, 2013 at 0:51
  • HTML tag : <a class="learn-more linkable" data-url="/speakers/minijambox">En savoir plus</a>
    – jbyogi
    Commented Dec 11, 2013 at 0:53
  • This is a localization test case. I am running the same url with other countries in my data provider.
    – jbyogi
    Commented Dec 11, 2013 at 0:54
  • @jbyogi, I've edited your question to put the HTML tag and the information about it being a localization test in the question body. Could you please edit the question to include the stack trace? Your link doesn't work for me.
    – Kate Paulk
    Commented Jan 7, 2014 at 13:04

2 Answers 2

2

The HTML tag you are trying to match has a class attribute and a data-url attribute but not an href attribute. Either you mistyped the HTML tag in your question or you need to change the definition of storeXpath2 to something like this:

String storeXpath2="//a[contains(@data-url,'"+url2+"')]";
                                  ^^^^^^^^ 
5
  • Your suggested solution didn't work. I used the same definition for different tag: String storeXpath="//a[contains(@href,'"+url+"')]"; driver.findElement(By.xpath(storeXpath)).click(); System.out.println("buy now for Mini"); and this seems to work fine.
    – jbyogi
    Commented Dec 11, 2013 at 1:10
  • Is it possible the same definition worked for a different tag because the different tag had an href attribute?
    – user246
    Commented Dec 11, 2013 at 2:14
  • It has the same tag as I mentioned in the original post.
    – jbyogi
    Commented Dec 11, 2013 at 21:28
  • But the tag you mentioned in the post did not have an href attribute. Quote: 'HTML tag : <a class="learn-more linkable" data-url="/speakers/minijambox">En savoir plus</a>'. What am I missing?
    – user246
    Commented Dec 11, 2013 at 21:42
  • yeah. But code does not work with data-url attribute.href works with storeXpath -url but it does not when i pass storexpath2-url2
    – jbyogi
    Commented Dec 11, 2013 at 21:55
0

What if you try:

String xpath = //li[@class="minijambox linkable"]/a[@href="/speakers/minijambox"]
2
  • 1
    does not seem to work.Thanks for the suggestion.
    – jbyogi
    Commented Dec 11, 2013 at 23:27
  • I checked for US and Spain locale, I do see the DOM hierarchy that you mention. I also verified with FirePath in Firebug and the xpath is identified. Another thing that I can think of is, you are trying to access the element before the page loads. A small wait might do the trick Commented Dec 12, 2013 at 0:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.