[英]Fetch all links using Selenium Python
In a webpage there are 15 links that starts with similar link names which are inside an iframe.在一个网页中,有 15 个链接以相似的链接名称开头,它们位于 iframe 中。 If I try to fetch those not all the links are fetched.
如果我尝试获取那些并非所有链接都被获取。 Below are the code I tried.
下面是我试过的代码。
driver = webdriver.Chrome(ChromeDriverManager().install())
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(("xpath", "//*[@id='brandBand_2']/div/iframe")))
wo_link1 = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located(("partial link text", 'SA')))
for link in wo_link1:
print(str(link.get_attribute("href")))
If I manually zoom out the webpage to the maximum extent, then I am able to get all the links.如果我手动将网页缩小到最大程度,那么我可以得到所有的链接。 Is there are any other ways to get those links without zooming out?
有没有其他方法可以在不缩小的情况下获取这些链接?
options = Options()
options.add_argument("start-maximized")
visibility_of_all_elements_located
will not actually wait for all the elements matching the passed locator to be visible. visibility_of_all_elements_located
实际上不会等待与传递的定位器匹配的所有元素都可见。 Actually it waits for at least 1 element matching the passed locator to be visible and then it returns all the matching elements caught at that moment.driver = webdriver.Chrome(ChromeDriverManager().install())
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(("xpath", "//*[@id='brandBand_2']/div/iframe")))
WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located(("partial link text", 'SA')))
time.sleep(1)
wo_links = driver.find_element(By.PARTIAL_LINK_TEXT, 'SA')
for link in wo_links:
print(str(link.get_attribute("href")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.