Selenium Python选项单击

2024-06-16 11:31:05 发布

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

我在一件小事上需要帮助, 看看这个:

enter image description here

我想按option名为Boleto Bancario,但要查看html

enter image description here

而不是如何使用selenium PYTHON按下第二个选项


Tags: html选项seleniumoptionboleto小事bancario
2条回答

您可以通过三种不同的方式在任何下拉列表中选择值:

select_by_value()
select_by_index()
select_by_visible_text()

因此,您只需选择如下选项:

select_by_value('813640')
select_by_index('1')
select_by_visible_text('Boleto Bancario')

希望这对你有用

请检查代码片段

  1. 您可以通过value进行选择
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome(r'chromedriver.exe')
driver.get('url')
sct = Select(driver.find_element_by_id('idFormaPagamento'))

sct.select_by_value('813640')
  1. 您可以通过index进行选择
sct.select_by_index('1')

相关问题 更多 >