Python Selenium,爬取动态下拉菜单

奇他巴拉姆

我正在使用Selenium和python进行网页抓取,以及用于测试此链接的页面

但是问题是我无法处理下拉菜单的动态内容,这是出现的问题

在选择州时,根据州来加载城市,据我所知,一些Php和js在后端运行。

因此,我在网上搜索了解决方案,等待一段时间,请使用此链接作为参考。

以下是我的代码的一部分

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait

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

chrome_path = r"E:\chromedriver.exe"

driver = webdriver.Chrome(chrome_path)

driver.get("http://www.blooddonors.in")
select = Select(driver.find_element_by_xpath('/html/body/table[3]/tbody/tr/td[2]/table[1]/tbody/tr/td/form/table/tbody/tr[2]/td[1]/select'))

select.select_by_visible_text('Tamil Nadu')
driver.implicitly_wait(60)
drop = Select(driver.find_element_by_xpath('//*[@id="div_city"]/select'))
select.select_by_visible_text('Coimbotore')

我正在使用Windows sys,并且尝试使用CMD。它不需要等待功能,没有它就可以正常工作。

我面临的错误是:

raise NoSuchElementException("Could not locate element with visible text: %s" % text)
selenium.common.exceptions.NoSuchElementException: Message: Could not locate element with visible text: Coimbotore

但是他们实际上是他们的。

如果有人可以帮助我解决问题,那就太好了,我可以继续进行下一个。

谢谢

DebanjanB

要选择Tamilnadu然后选择,Coimbotore您可以使用以下代码块:

driver.get("http://www.blooddonors.in")
select = Select(driver.find_element_by_name('select'))
select.select_by_visible_text('Tamil Nadu')
drop = Select(driver.find_element_by_name('city'))
city_option = WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath("//select[@name='city']/option[text()='Coimbotore']"))
city_option.click()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Selenium Python的下拉菜单中选择动态元素

硒python动态下拉菜单

Python中的Selenium-下拉菜单

下拉菜单的python

下拉菜单 python

Python Selenium - 从下拉菜单中选择值

在Python中单击带有Selenium的下拉菜单

下拉菜单可用后,Python Selenium单击按钮

Python Selenium-单击下拉菜单后选择

如何使用Python使用Selenium选择下拉菜单值?

如何使用Python使用Selenium选择下拉菜单值?

识别表中的下拉菜单(Python中的Selenium)

如何使用 Python 在 Selenium 上选择下拉菜单

使用Python + Selenium选择一个下拉菜单

Python Selenium无法选择下拉菜单(Chrome WebDriver)

无法在iframe中单击下拉菜单-Selenium Python

使用 selenium Python 库单击下拉菜单中的项目

无法使用 Selenium Python 选择更多下拉菜单

Python Tkinter下拉菜单

使用python从下拉菜单中删除所有动态生成的数据的最佳方法

如何使用Selenium和Python从下拉菜单中选择一个选项

如何从python selenium的下拉菜单中选择一个值

如何使用带有 Python 的 Selenium Webdriver 抓取下拉菜单选项?

使用Python Selenium从下拉菜单中获取当前的<select>值

无法从下拉菜单Python Selenium中选择一个选项

使用selenium和python从下拉菜单中选择一个选项

使用Selenium和python选择下拉菜单时遇到问题

很难点击激活下拉菜单的单选按钮。使用Selenium和Python

如何使用Selenium和Python提取下拉菜单的所选选项的文本