【问题标题】:InvalidArgumentException: Message: invalid argument: invalid locator error comingInvalidArgumentException:消息:无效参数:出现无效定位器错误
【发布时间】:2022-01-21 09:41:19
【问题描述】:

我正在做一个与航班价格相关的项目,当我在网上搜索部门时遇到错误。 网址是https://flight.yatra.com/air-search-ui/dom2/trigger?ADT=1&CHD=0&INF=0&class=Economy&destination=BOM&destinationCountry=IN&flexi=0&flight_depart_date=22%2F01%2F2022&hb=0&noOfSegments=1&origin=DEL&originCountry=IN&type=O&unique=254010891105&viewName=normal

我的代码是:

dept_time=driver.find_elements("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")
dept= []
for i in dept_time:
    a = i.get_attribute('innerText')
    print(a)
    dept.append(a)
print(dept)

我也试过"//div[@class='i-b pr']

但我收到了同样的错误

【问题讨论】:

  • 它是刮、刮、刮——废是完全不同的东西。

标签: python selenium selenium-webdriver xpath


【解决方案1】:

代替

dept_time=driver.find_elements("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")

试试

dept_time=driver.find_elements_by_xpath("//div[@class='i-b col-4 no-wrap text-right dtime col-3']")

或者

dept_time=driver.find_elements(By.XPATH, "//div[@class='i-b col-4 no-wrap text-right dtime col-3']")

另外,不要忘记等待/延迟与代码一起使用,以便在您阅读其内部文本之前加载元素。

【讨论】:

    猜你喜欢
    • 2016-06-08
    • 1970-01-01
    • 2020-06-09
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多