driver.find_elements_by_tag_name('tr')
时间: 2024-05-20 07:16:07 浏览: 111
This line of code finds all the HTML elements with the tag name "tr" on the web page using the Selenium WebDriver. It returns a list of all the elements found with that tag name. "tr" is the tag name for table rows in HTML.
相关问题
driver.find_elements_by_tag_name('tr') 的写法有哪些
1. 直接使用 driver.find_elements_by_tag_name('tr')。
2. 使用变量存储 tag_name,例如 tag_name = 'tr',再使用 driver.find_elements_by_tag_name(tag_name)。
3. 将 driver 存储在变量中,例如 driver = webdriver.Chrome(),再使用 driver.find_elements_by_tag_name('tr')。
4. 将 find_elements_by_tag_name 存储在变量中,例如 find_elements = driver.find_elements_by_tag_name,再使用 find_elements('tr')。
修改这段代码 # 打开浏览器 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()
阅读全文