首页 > 解决方案 > 我正在尝试使用提到的代码找到可点击/不可点击的墨水并在控制台中打印它

问题描述

此代码正在从给定的 URL 中提取链接。想要从提取的链接中划出可点击和不可点击的链接。

from selenium import webdriver       
import time    

ccount=0   
ncount=0

URL = input('Enter URL: ')

driver = webdriver.Chrome()

URL = input('Enter URL: ')

driver.get(URL)

time.sleep(2)

ids = driver.find_elements_by_xpath('//*[@href]')

for a in ids:

    print(a.get_attribute('href'))    

标签: pythonseleniumwebdriver

解决方案


Selenium 中没有特定/预定义的可点击链接方法,我们必须执行点击操作并验证任何 UI 元素/元素属性

循环 clickableCount 数组

1. Save the current web url
2. Click on the link
3. Check whether URL changed or not and continue until end

推荐阅读