有人能帮我找到RPAFramew中的元素吗

2024-09-26 22:52:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过元素“tr”的xpath迭代表行搜索。但是当我试图找到元素“td”来迭代它们并获取文本时,我得到了错误“invalid locator”。这只是个测试,有人能帮我吗?代码如下:

from RPA.Browser.Selenium import Selenium

lib = Selenium()

lib.open_available_browser("https://ge.globo.com/futebol/brasileirao-serie-a/")
lib.wait_until_element_is_visible('xpath://*[@id="classificacao__wrapper"]/article/section[1]/div/table[2]/tbody/tr')
trs = lib.find_elements('xpath://*[@id="classificacao__wrapper"]/article/section[1]/div/table[2]/tbody/tr')

for tr in trs:
    td = tr.find_elements('tag:td')
    print(td)

Tags: divid元素libseleniumarticletablesection
1条回答
网友
1楼 · 发布于 2024-09-26 22:52:37

好吧,我找到答案了。RPAFramework的python文档非常混乱,在模块“webelement”中搜索时,我发现“find_elements”方法不起作用。我需要替换为“按标签名称查找元素”。下面是代码:

from RPA.Browser.Selenium import Selenium

lib = Selenium()

lib.open_available_browser("https://ge.globo.com/futebol/brasileirao-serie-a/")
lib.wait_until_element_is_visible('xpath://*[@id="classificacao__wrapper"]/article/section[1]/div/table[2]/tbody/tr')
trs = lib.find_elements('xpath://*[@id="classificacao__wrapper"]/article/section[1]/div/table[2]/tbody/tr')

for tr in trs:
    tds = tr.find_elements_by_tag_name('td')
    for td in tds:
        print(td.text)

相关问题 更多 >

    热门问题