我试图循环浏览网页上的链接列表,使用selenium单击每个链接,然后从每个页面复制一个tinylink,最后返回到主列表页面。到目前为止,它将访问该页面,但我正在努力获得
单击链接->;加载页面->;单击“共享”->;单击“复制”
目前,它正在访问主列表页面,直接点击“共享”,然后点击第一个链接。也许我想得太多了,因为我认为睡眠(1)会把程序缩短到下一步。请帮忙
#below accesses each link, opens the tinylink, and copies it
powerforms = driver.find_element_by_xpath("//*[@id='main-content']/ul")
links = powerforms.find_elements_by_tag_name("li")
for link in links:
link.click()
sleep(1)
#clicks 'Share' button to open popout
share = driver.find_element_by_id("shareContentLink")
share.click()
sleep(1)
#clicks 'Copy' button to copy the tinylink to the clipboard
copy = driver.find_element_by_id("share-link-copy-button")
copy.click()
sleep(1)
break
您应该使用
WebDriverWait
而不是sleep,以确保元素出现在页面上、已加载且可交互。睡眠不考虑你的上网速度等相关问题 更多 >
编程相关推荐