硒 - 下拉菜单

发布于 2025-02-06 13:04:28 字数 455 浏览 5 评论 0原文

我正在尝试刮擦本网站上生成的电子表格: htttps:httpps://sisaps.saude.saude.saude。 gov.br/sisvan/relatoriopublico/index

首先,您需要在顶部单击“ estado nutricional -selecionarrelatório”此下拉菜单的ID。我已经尝试过:

driver.find_element(by.id,'nuano')。select_by_value('2009'),

但我会遇到此错误:

'webelement'对象没有属性'select_by_value'。

如何找到它? 谢谢!

I'm trying to scrape spreadsheets generated in this website: https://sisaps.saude.gov.br/sisvan/relatoriopublico/index

First you need to click on "Estado nutricional -> Selecionar relatório" on the top, then select a year at "Ano de Referência:", but I can't find an ID for this dropdown menu. I have tried this:

driver.find_element(By.ID, 'nuAno').select_by_value('2009')

But I get this error:

'WebElement' object has no attribute 'select_by_value'.

How to find it?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书间行客 2025-02-13 13:04:28

确保元素已找到:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(self.driver, 50).until(
                EC.presence_of_element_located((By.ID, "nuAno")))

另外,请确保您使用的是:

from selenium.webdriver.support.ui import Select

Select(element).select_by_value("2009")

Make sure the element is located:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(self.driver, 50).until(
                EC.presence_of_element_located((By.ID, "nuAno")))

Also make sure you are using Select:

from selenium.webdriver.support.ui import Select

Select(element).select_by_value("2009")
稳稳的幸福 2025-02-13 13:04:28

我使用

from seleniumbase import BaseCase

class RecorderTests(BaseCase):
    def test_recording(self):
        self.open("https://sisaps.saude.gov.br/sisvan/relatoriopublico/index")
        self.click('strong:contains("SELECIONAR RELATÓRIO")')
        self.click('button[title="-SELECIONE-"]')
        self.select_option_by_text("select#nuAno", "2019")

”葡萄牙语版本:

from seleniumbase.translate.portuguese import CasoDeTeste

class RecorderTests(CasoDeTeste):
    def test_recording(self):
        self.abrir("https://sisaps.saude.gov.br/sisvan/relatoriopublico/index")
        self.clique('strong:contains("SELECIONAR RELATÓRIO")')
        self.clique('button[title="-SELECIONE-"]')
        self.selecionar_opção_por_texto("select#nuAno", "2019")

使用 seleniumbase 您可以使用pytest 。添加- demo选项以减慢测试,以便您看到发生的事情。 (全面披露:我构建了Seleniumbase框架。)

I used the SeleniumBase Recorder to generate the script:

from seleniumbase import BaseCase

class RecorderTests(BaseCase):
    def test_recording(self):
        self.open("https://sisaps.saude.gov.br/sisvan/relatoriopublico/index")
        self.click('strong:contains("SELECIONAR RELATÓRIO")')
        self.click('button[title="-SELECIONE-"]')
        self.select_option_by_text("select#nuAno", "2019")

There's also the Portuguese version:

from seleniumbase.translate.portuguese import CasoDeTeste

class RecorderTests(CasoDeTeste):
    def test_recording(self):
        self.abrir("https://sisaps.saude.gov.br/sisvan/relatoriopublico/index")
        self.clique('strong:contains("SELECIONAR RELATÓRIO")')
        self.clique('button[title="-SELECIONE-"]')
        self.selecionar_opção_por_texto("select#nuAno", "2019")

With SeleniumBase installed, you can run the scripts with pytest. Add the --demo option to slow down the tests so that you can see what's happening. (Full disclosure: I built the SeleniumBase framework.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文