2014-02-25 212 views
0

我是新来的硒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。

<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> 

回答

0

我没有用Selenium IDE的,但我已经使用硒的webdriver的Python类似于

你只需要通过CSS选择找到你的元素,特别是结构的选择;这可能是最简单的方法,如果你不得不挖掘很多没有ID /类的标记

CSS有后代选择器和伪元素选择器,它们允许你只根据它们的位置来定位特定的元素的DOM,而不需要一个id或类

可以使用:nth-of-type()伪元件,其靶向基于传递到它的

例如以纯的CSS数目该元素的具体发生:

a:第n种(1)

将在主体内看起来并选择第一个类型。如果你使用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)") 

你可以用它来针对第一,第二,第三等元素。如果你需要根据特定属性值定位一个元素,也有css属性选择器。

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

祝你好运mayne。 cholla cholla hee haw

+0

谢谢你的回答,那是webdriver的权利吗?我的问题是:( – Junosaur

+0

如果你必须使用xpath的硒ide,你可以不指定像“// a [1]”或“//a [2]”锚?像数组一样,它会发现第n次出现该元素,在你的情况下,它是一个锚点 –

+0

,如果链接处于相同的/ 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] 无论如何,如果这是不可能在硒ide,也许我会只使用硒webdrive r我只是不知道从哪里开始LOL非常感谢你,他非常喜欢chola他喜欢哦 – Junosaur