Pet*_*tit 1 javascript selenium xpath web-scraping python-3.x
我无法使用 Xpath 和 Selenium 单击按钮,在这种情况下,aria-label 具有唯一的日期,可以完美地区分日历中的其他一些按钮。
这是显示第 5 天和当天价格的按钮的 HTML 代码。
<button type="button" class="CalendarDay__button" aria-label="Choose sunday, february 4 2018 as your check-in date. It's available." tabindex="0"><div class="calendar-day"><div class="day">4</div><div class="flybondi font-p fare-price"><span>$728*</span></div></div></button>
<button type="button" class="CalendarDay__button" aria-label="Choose monday, february 5 2018 as your check-in date. It's available." tabindex="0"><div class="calendar-day"><div class="day">5</div><div class="flybondi font-p fare-price"><span>$728*</span></div></div></button>Run Code Online (Sandbox Code Playgroud)
#假设我想点击 2018 年 2 月 5 日,我试过了
dtd0_button = driver.find_element_by_xpath("//button[contains(@class, 'CalendarDay__button') and (@aria-label, 'Choose monday, February 5 2018 as your check-in date. It's available') ]")
dtd0_button.Click()
Run Code Online (Sandbox Code Playgroud)
这种方法有什么问题,如果我可以单击网页日历中的任何日期,我会收到以下消息“WebElement”对象没有属性“单击”。
您的 xpath 有几个错误,使其无效:
首先,您必须contains在每个条件之前声明:
"//button[contains(@attribute1, \"content1\") and contains(@attribute2, \"content2\")]"
Run Code Online (Sandbox Code Playgroud)在'您的XPath内部没有逃脱。请尝试以下操作:
"//button[contains(@class,\"CalendarDay__button\") and contains(@aria-label,\"Choose monday, february 5 2018 as your check-in date. It's available.\")]"
Run Code Online (Sandbox Code Playgroud)希望能帮助到你。祝你好运!
| 归档时间: |
|
| 查看次数: |
13417 次 |
| 最近记录: |