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.
-
1Can you provide a Stack trace of errors being thrown? Also, the html snippet of the <a> tag you are trying to access might help tooSuchit Parikh– Suchit Parikh2013年12月11日 00:31:46 +00:00Commented Dec 11, 2013 at 0:31
-
stack Trace : openid.stackexchange.com/affiliate/…jbyogi– jbyogi2013年12月11日 00:51:56 +00:00Commented Dec 11, 2013 at 0:51
-
HTML tag : <a class="learn-more linkable" data-url="/speakers/minijambox">En savoir plus</a>jbyogi– jbyogi2013年12月11日 00:53:41 +00:00Commented 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– jbyogi2013年12月11日 00:54:58 +00:00Commented 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– Kate Paulk2014年01月07日 13:04:14 +00:00Commented Jan 7, 2014 at 13:04
2 Answers 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+"')]";
^^^^^^^^
-
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– jbyogi2013年12月11日 01:10:39 +00:00Commented 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– user2462013年12月11日 02:14:00 +00:00Commented Dec 11, 2013 at 2:14 -
It has the same tag as I mentioned in the original post.jbyogi– jbyogi2013年12月11日 21:28:40 +00:00Commented 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– user2462013年12月11日 21:42:40 +00:00Commented 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-url2jbyogi– jbyogi2013年12月11日 21:55:29 +00:00Commented Dec 11, 2013 at 21:55
What if you try:
String xpath = //li[@class="minijambox linkable"]/a[@href="/speakers/minijambox"]
-
1does not seem to work.Thanks for the suggestion.jbyogi– jbyogi2013年12月11日 23:27:30 +00:00Commented 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 trickSuchit Parikh– Suchit Parikh2013年12月12日 00:26:17 +00:00Commented Dec 12, 2013 at 0:26