Please help me to create the Xpath for the following href. I am using Selenium webdriver and have only IE browser. Following is the HTML: Need Xpath for : a href="javascript:OnEventQueue();">. I can use only IE browser and need to click on this link.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Transitional//EN"><META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<html>
<body>
<form name="runevent1" action="/epace/epace-cgi/eglcgids.exe?sessionid=" method="post" btnSubmit="javascript:preSumbit()" EParams="http://vaim1-apt-120/epace/epace-cgi/eglcgids.exe?sessionid=&Action=runevent1&EventType=&EventInst=#" EParamOptions="http://vaim1-apt-120/epace/epace-cgi/eglcgids.exe?sessionid=&Action=runevent1&EventType=&EventInst=#">
<table width="100%" align="center" border="0">
<tbody>
<tr class="topMenu">
<td align="right">
<span id="idSpanActionLinks">
<a href="javascript:OnEventQueue();">
<font class="topMenu">Event Queue</font>
</a>
</span>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Use the following algorithms to select your elements.
element[attribute(^|*|$|~)='attribute value']
//element[(@attribute|contains|starts-with|ends-with(@attribute, 'value'))='value'
The xpath is a little bit uglier, and definitely not correct, but the CSS algorithm is correct.
When you want to match on ANY property, including href
like you want to, use this algorithm.
Ask yourself these questions:
In your case, the answer to #1 is an <a>
. Answer to number #2 is href
. Answer #3, is probably not because there could be more href
's like this. whereas ID's, are usually unique. (it is called an identifier after all). what you can do is look at the parent and use it's ID.
In CSS : span#idSpanActionLinks > a
will work just fine. (* #
is just a css shortcut for id see here )
In Xpath : //span[@id='idSpaceActionLinks']/a
After your comment, since you are wanting to match href
, here you go:
a[href*='OnEventQueue']
//a[contains(@href, 'OnEventQueue')]
Both will work.
Note that both of these statements mean, in English:
find me an
<a>
element, whose attributehref
contains the valueOnEventQueue
The XPath is not unique. For different levels of "precision", you can have different paths.
Eg:
//*[@id="idSpanActionLinks"]/a
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.