如何为此创建适合 Selenium 的 XPath?

How to create an XPath for this, suitable for Selenium?

请帮助我为以下内容创建 Xpath。我正在使用 Selenium webdriver 并且只有 IE 浏览器。以下是 HTML:

<A
    title=""
    href="javascript:Plg({u:'/epace/starintfc.html?module=RUN_EVENT',p:0,nw:'0'});"
    p="eagle/pace/pace"
    la=""
    ml="%09NULL%09PLUGIN%09%2fepace%2fstarintfc.html%3fmodule%3dRUN_EVENT%09%09%09%09%09%09%09%09%09%09"
    t="Plugin" gh="" g="Data Steward"
    pc="Eagle/PACE/PACE Components"
    ivname=""
><IMG id=Item.Img
      class=link
      src="/tpe/modules/site/img/menu_plugin.gif">Run An Event</A>

我更喜欢 CSS 而不是 xPath,因为它很简单,我将同时提供 CSS 和 xPath 解决方案:

请记住,您想要获取最具体的元素的属性。下面的答案是我力所能及的,以确定哪些具有最大的特异性。 (see here 如果你想了解更多关于 CSS 和元素的特殊性)

If you are trying to select the first <a> element...

CSS:

a[href*='RUN_EVENT']

xPath:

//a[contains(@href, 'RUN_EVENT')]

If you are trying to select the <img> that is inside of the <a> tag...

CSS:

a[href*='RUN_EVENT'] > img

xPath:

//a[contains(@href, 'RUN_EVENT')]/img

我的猜测是您想要第一个,因为它是 link,我假设您想要调用它。