Html 单击Selenium IDE中的多个链接

Html 单击Selenium IDE中的多个链接,html,selenium,xpath,selenium-ide,Html,Selenium,Xpath,Selenium Ide,我是selenium ide新手,我想自动化一些网站。我希望它是这样的 点击 Click Link 1 do some clicking inside that link go back to the list of link Click Link 2 do some clicking inside that link go back to the list of link Click Link 3 and so on 我唯一的问题是,我不知道它将如何单击顶部的第一个链接。这是网站的html

我是selenium ide新手,我想自动化一些网站。我希望它是这样的

点击

Click Link 1
do some clicking inside that link
go back to the list of link
Click Link 2
do some clicking inside that link
go back to the list of link
Click Link 3
and so on
我唯一的问题是,我不知道它将如何单击顶部的第一个链接。这是网站的html

<h5>20 seconds ago</h5>
<ul>
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png">
<a href="/account/54351-wews">wews</a>
send new
<a href="/news/53235">post</a> **Link 1**
</li>
</ul>
<h5>3 minutes ago</h5>
<ul>
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png">
<a href="/account/632323-yokol">yokol</a>
submitted a new
<a href="/news/253129-loss">post</a> **Link 2**
</li>
</ul>
<h5>4 minutes ago</h5>
<ul>
<h3>6 minutes ago</h3>
<ul>
<h5>7 minutes ago</h5>
<ul>
<h2>8 minutes ago</h2>
<ul>
<li class="notification-posted">
<li class="notification-posted">
<li class="notification-posted">
<li class="notification-posted">
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png">
<a href="/account/153316-problem">hey</a>
send new
<a href="/news/25151-helloworld">post</a> **link 3**
</li>
</ul>
20秒前
  • 发送新的 **链接1**
3分钟前
  • 提交了一份新的 **链接2**
4分钟前
    6分钟前
      7分钟前
        8分钟前
        • 发送新的 **链接3**

我没有使用Selenium ide,但我使用了类似于python的Selenium Webdriver

您只需要通过css选择器定位元素,特别是结构选择器;如果您必须挖掘大量没有ID/类的标记,那么这可能是最简单的方法

CSS有子代选择器和psuedo元素选择器,它们允许您仅根据特定元素在DOM中的位置来定位它们,而不需要id或类

您可以使用
:nth-of-type()

例如,在纯css中:

a:第n种类型(1)

将查看主体内部并选择其类型的第一个a。如果改为使用2,它将针对锚点的第二个引用

例如,在selenium.webdriver中,您可以这样找到您的元素:

# ff is the webdriver.Firefox() instance

firstAnchor = ff.find_element_by_css_selector("a:nth-of-type(1)")

secondAnchor = ff.find_element_by_css_selector("a:nth-of-type(2)")
您可以使用它来瞄准第1、第2、第3等元素。如果您需要基于特定属性值以元素为目标,那么也有css属性选择器

ff.find_element_by_css_selector("a[href='/account/54351-wews']")

祝你好运,梅恩。cholla cholla hee haw

谢谢您的回答,这是给webdriver的,对吗?我的问题是ide:(如果您必须为selenium ide使用xpath,您能不能指定像“//a[1]”或“//a[2]”这样的锚点?像数组一样,它会找到该元素的第n次出现,在您的例子中,它是一个锚点,如果链接在同一个/ul中,它将工作;如果是这样的话,xpath将是这样的//div[@id='main']/ul[1]/li[1][@class='notification-posted']/a[2]//div[@id='main']/ul[1]/li[2][@class='notification-posted']]/a[2]它不能像此链接那样单击其他/ul中的链接。//div[@id='main']/ul[2]/li[@class='notification-posted']/a[2]无论如何,如果这在selenium ide中是不可能的,也许我会使用selenium webdriver我只是不知道从哪里开始LOL谢谢你这么多chola chola他唧唧哦耶耶耶耶耶