Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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.

share|improve this question
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 –  Suchit Parikh Dec 11 '13 at 0:31
    
stack Trace : openid.stackexchange.com/affiliate/… –  jbyogi Dec 11 '13 at 0:51
    
HTML tag : <a class="learn-more linkable" data-url="/speakers/minijambox">En savoir plus</a> –  jbyogi Dec 11 '13 at 0:53
    
This is a localization test case. I am running the same url with other countries in my data provider. –  jbyogi Dec 11 '13 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 Jan 7 at 13:04
add comment

2 Answers

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+"')]";
                                  ^^^^^^^^ 
share|improve this answer
    
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 Dec 11 '13 at 1:10
    
Is it possible the same definition worked for a different tag because the different tag had an href attribute? –  user246 Dec 11 '13 at 2:14
    
It has the same tag as I mentioned in the original post. –  jbyogi Dec 11 '13 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 Dec 11 '13 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 Dec 11 '13 at 21:55
add comment

What if you try:

String xpath = //li[@class="minijambox linkable"]/a[@href="/speakers/minijambox"]
share|improve this answer
1  
does not seem to work.Thanks for the suggestion. –  jbyogi Dec 11 '13 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 –  Suchit Parikh Dec 12 '13 at 0:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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