擅长:python、mysql、java
<p>您应该能够使用下面的逻辑打开新选项卡中的所有详细信息链接。在</p>
<pre><code>driver.get("https://xxxxxx/blogs/")
if driver.find_element_by_xpath("(//span[@class='ui-datepicker-month'][contains(.,'May')])[1]"):
main_window = driver.current_window_handle
# get the number of details to click
addr = len(driver.find_elements_by_xpath("//a[@class='details'][contains(.,'Details')]"))
# iterate through all the details links (used the index rather elements list as it may lead to staleeleemnt exception after clicking on the first detiails link)
for addrNum in range(addr):
# get the details element based on index
ele = driver.find_element_by_xpath("(//a[@class='details'][contains(.,'Details')])[" + str (addrNum+1) + "]")
# get the href of the link
href = ele.get_attribute('href')
# open the href in another tab
driver.execute_script("window.open('" + href +"');")
# switching to parent window (on safer side)
driver.switch_to.window(main_window)
</code></pre>