【问题标题】:get a table element using Selenium使用 Selenium 获取表格元素
【发布时间】:2021-09-29 04:26:15
【问题描述】:

我是 selenium 新手,想知道如何识别表格列信息,在这种情况下,可以使用 selenium 下载文件的“Em aberto”字段。

我的代码:

from selenium import webdriver

from time import sleep

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

navegador = webdriver.Chrome()

link = "https://app.gdjeokdk.com/login"

navegador.get(link)

user = "******"

password = "******"

sleep(1)

campo_user = navegador.find_element_by_id('login-input-usuario-id').send_keys(user)

campo_password = navegador.find_element_by_name('senha').send_keys(password)

button_enter = navegador.find_element_by_id('login-button-id').click()

sleep(5)

button_consultas = navegador.find_element_by_id("menu-consultas").click()

sleep(3)

iframe = navegador.find_element_by_id("iframeRf")

navegador.switch_to.frame(iframe)

sleep(2)

fatura = navegador.find_element_by_id("consultaspnl.row.8").click()

sleep(2)

#arquivo = navegador.find_element_by_id("g.image.visualizar").click()

table_id = navegador.find_element_by_id('faturaspnl.orderedflextablemo.tabela')

print(table_id)

sleep(1)

rows = table_id.find_elements_by_tag_name("tr") 
#print(rows)
for row in rows:       
    col = row.find_elements(By.TAG_NAME, "td")
    print(col)
#     for linhas in col:
#         if "Em aberto" in linhas[2].find_element_by_class_name("gwt-HTML"):
#             div = linhas.find_elements(By.TAG_NAME, "div")
#     print(div)


如果需要,我会拍下桌子的照片: Table

HTML 如果需要: HTML code

在识别具有“Em Aberto”信息的行后,如何获得“Visualizar”按钮?

HTML代码2codigo HTML 2

【问题讨论】:

    标签: python html selenium selenium-webdriver


    【解决方案1】:

    你可以试试这样的:

    items = navegador.find_element_by_xpath("//td[@class='dataBaseTD nomeTD']/div[text()="Em aberto"]")
    

    看看https://selenium-python.readthedocs.io/locating-elements.html

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-16
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多