find_elements(by=By.TAG_NAME, value=name) 怎么用
时间: 2023-06-01 20:05:43 浏览: 166
"find_elements(by=By.TAG_NAME, value=name)" 是 Selenium 的一个方法,用于通过标签名字查找网页元素,其中的'name'需要替换成具体的标签名。例如,查找所有的<a>标签,可以写成: find_elements(by=By.TAG_NAME, value='a')。
相关问题
修改这段代码 # 打开浏览器 driver = webdriver.Chrome() # 打开网页 driver.get("http://10.0.1.230:8080/#/SampleExtraction/cmm/146") # 打开网页 driver.get("http://10.0.1.230:8080/#/RNAinstance/cmm/20") # 找到表格元素 table = driver.find_element_by_id("table") # 获取表格内容 rows = table.find_elements_by_tag_name("tr") table_list = [] for row in rows: cols = row.find_elements_by_tag_name("td") row_list = [] for col in cols: row_list.append(col.text) table_list.append(row_list) # 将表格内容复制到剪贴板中 table_string = "" for row in table_list: for col in row: table_string += col + "\t" table_string += "\n" pyperclip.copy(table_string) # 打开目标软件 driver.get("http://10.0.1.230:8080/#/SampleExtraction/cmm/146") # 定位目标位置并粘贴表格内容 target_position = driver.find_element_by_id("target") target_position.send_keys(Keys.CONTROL, 'v') # 在整体订单中改到预审 input_box = driver.find_element_by_id("input-box") input_box.send_keys("value") button = driver.find_element_by_id("button") button.click() # 打开目标软件 driver.get("http://10.0.1.230:8080/#/RNAinstance/cmm/20") # 定位目标位置并粘贴表格内容 target_position = driver.find_element_by_id("target") target_position.send_keys(Keys.CONTROL, 'v') # 提交预审 input_box = driver.find_element_by_id("input-box") input_box.send_keys("value") button = driver.find_element_by_id("button") button.click() # 关闭浏览器 driver.quit() ```
# 打开浏览器
driver = webdriver.Chrome()
# 打开第一个网页
driver.get("http://10.0.1.230:8080/#/SampleExtraction/cmm/146")
# 找到表格元素
table = driver.find_element_by_id("table")
# 获取表格内容
rows = table.find_elements_by_tag_name("tr")
table_list = []
for row in rows:
cols = row.find_elements_by_tag_name("td")
row_list = []
for col in cols:
row_list.append(col.text)
table_list.append(row_list)
# 将表格内容复制到剪贴板中
table_string = ""
for row in table_list:
for col in row:
table_string += col + "\t"
table_string += "\n"
pyperclip.copy(table_string)
# 定位目标位置并粘贴表格内容
target_position = driver.find_element_by_id("target")
target_position.send_keys(Keys.CONTROL, 'v')
# 在第一个网页中提交预审
input_box = driver.find_element_by_id("input-box")
input_box.send_keys("value")
button = driver.find_element_by_id("button")
button.click()
# 关闭第一个网页
driver.quit()
# 打开第二个网页
driver = webdriver.Chrome()
driver.get("http://10.0.1.230:8080/#/RNAinstance/cmm/20")
# 定位目标位置并粘贴表格内容
target_position = driver.find_element_by_id("target")
target_position.send_keys(Keys.CONTROL, 'v')
# 在第二个网页中提交预审
input_box = driver.find_element_by_id("input-box")
input_box.send_keys("value")
button = driver.find_element_by_id("button")
button.click()
# 关闭第二个网页
driver.quit()
'WebDriver' object has no attribute 'find_elements_by_tag_name'
This error message is indicating that the 'WebDriver' object you are using does not have a method called 'find_elements_by_tag_name'.
Possible solutions could include:
- Check if you have misspelled the method name or if there is a typo in your code.
- Make sure you are using the correct version of the WebDriver for your browser.
- Try importing the method from the 'selenium.webdriver.common.by' module and using it as 'driver.find_elements(by=By.TAG_NAME, value='tag_name')'.
- Check if there is a different method available that serves the same purpose, such as 'find_elements_by_xpath' or 'find_elements_by_css_selector'.
阅读全文