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.

alecxe
11.4k11 gold badges52 silver badges107 bronze badges
asked Dec 11, 2013 at 0:05
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/… Commented Dec 11, 2013 at 0:51
  • HTML tag : <a class="learn-more linkable" data-url="/speakers/minijambox">En savoir plus</a> 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. 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. 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+"')]";
 ^^^^^^^^ 
answered Dec 11, 2013 at 1:01
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. 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? Commented Dec 11, 2013 at 2:14
  • It has the same tag as I mentioned in the original post. 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? 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 Commented Dec 11, 2013 at 21:55
0

What if you try:

String xpath = //li[@class="minijambox linkable"]/a[@href="/speakers/minijambox"]
answered Dec 11, 2013 at 22:25
2
  • 1
    does not seem to work.Thanks for the suggestion. 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

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.