selenium webdriver刷新并验证属性是否发生更改

2024-10-02 00:38:05 发布

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

我尝试使用Python和Selenium webdriver刷新一个页面,直到元素保持启用状态并单击。唯一的问题是刷新页面并进行验证。 这是一个用来做一个提示的日历。该页面的代码摘录如下:

<tr>

<td title="Not able" class="otherMonthDay">30</td>
<td title="Not able" class="otherMonthDay">31</td>
<td title="All busy" class="calendarCellRed">1</td>
<td title="Not able" class="noSelectableDay">2</td>
<td title="All busy" class="calendarCellRed">3</td>
<td title="Not able" class="noSelectableDay">4</td>
<td title="Not able" class="noSelectableDay">5</td>

</tr>

我的代码是:

^{pr2}$

我想在页面刷新时单击启用的日期。在


Tags: 代码titleseleniumnotable页面alltr
1条回答
网友
1楼 · 发布于 2024-10-02 00:38:05

我猜当你执行上面的代码时,你会得到一个NoSuchElementException。在

我的代码是这样的:

from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.implicitly_wait(2)
alert = driver.switch_to_alert()

driver.get("https://calendar page css")

while(True):
   try:
      driver.find_element_by_xpath('//*[@title="Day enabled"]').click()
      driver.refresh()
      alert.accept()
      break
   except Exception as e:
      driver.refresh()
      continue

希望这有帮助。如果有任何问题,一定要告诉我。在

相关问题 更多 >

    热门问题