Html 如何使用Selenium单击第三个Div类;链接';如果他们都共享同一个Div类?

Html 如何使用Selenium单击第三个Div类;链接';如果他们都共享同一个Div类?,html,python-3.x,selenium,click,Html,Python 3.x,Selenium,Click,我将selenium与python一起使用。所有HTML共享相同的div类“links”。页面上总共有七个链接,每个链接都具有相同的类和部分相同的名称。我想知道如果web元素的名称完全相同,如何单击它们 Selenium与python一起使用chrome webdriver <div class="aux"> <div class="links"> <a class="view" href=&

我将selenium与python一起使用。所有HTML共享相同的div类“links”。页面上总共有七个链接,每个链接都具有相同的类和部分相同的名称。我想知道如果web元素的名称完全相同,如何单击它们

Selenium与python一起使用chrome webdriver

<div class="aux">
  <div class="links">
     <a class="view" href="/pmc/articles/PMC1403861/">Summary</a>
     <a class="view" href="/pmc/articles/PMC1403861/?report=classic&amp;page=1">Page Browse</a>
     <a class="view" href="/pmc/articles/PMC1403861/pdf/jeabehav00206-0003.pdf">PDF–1.6M</a>
     <a class="view citationexporter" href="#" data-citationid="PMC1403861" role="button" aria-expanded="false" aria-haspopup="true">Citation</a>
  </div>
</div>


您可以使用XPath对元素进行索引

e、 g:

//div[@class='links']/a[3]

//div[@class='links']//following::a[3]

有关更多详细信息,请参阅以下URL:


您可以使用XPath对元素进行索引

e、 g:

//div[@class='links']/a[3]

//div[@class='links']//following::a[3]

有关更多详细信息,请参阅以下URL:


您可以使用css选择器,如下面所示:

.find_element_by_css_selector('div.links a[href*="pdf"]').click()
或者,如果要使用序列:

.find_element_by_css_selector('div.links a:nth-child(3)').click()
参考:


您可以使用css选择器,如下面所示:

.find_element_by_css_selector('div.links a[href*="pdf"]').click()
或者,如果要使用序列:

.find_element_by_css_selector('div.links a:nth-child(3)').click()
参考:


尝试使用以下语法-

Python:

 driver.find_element_by_xpath("//div[@class = 'links']/a[3]")).click();
爪哇:


尝试使用下面的语法-

Python:

 driver.find_element_by_xpath("//div[@class = 'links']/a[3]")).click();
爪哇:


查找具有类名链接的第三个类

elem=driver.find_elements_by_xpath("//div[@class='links']")[3]

elem=driver.find_element_by_css_selector("div.links:nth-child(3)")

查找具有类名链接的第三个类

elem=driver.find_elements_by_xpath("//div[@class='links']")[3]

elem=driver.find_element_by_css_selector("div.links:nth-child(3)")