admin管理员组文章数量:1125610
I'm using Selenium to target and click on table that has modal with information in it to perform an action. In the table there could be 1 or more rows. The script runs fine first time I start the computer and run it, if there is two or more rows to click it still runs fine at first run. However on second test it ignores the first clickable row and gives error:
Error processing state0 booking 1: Message:
Stacktrace:
GetHandleVerifier [0x00007FF62116FB05+28789]
(No symbol) [0x00007FF6210D86E0]
(No symbol) [0x00007FF620F7592A]
(No symbol) [0x00007FF620FC930E]
(No symbol) [0x00007FF620FC95FC]
(No symbol) [0x00007FF6210128A7]
(No symbol) [0x00007FF620FEF47F]
(No symbol) [0x00007FF62100F654]
(No symbol) [0x00007FF620FEF1E3]
(No symbol) [0x00007FF620FBA938]
(No symbol) [0x00007FF620FBBAA1]
GetHandleVerifier [0x00007FF6214A933D+3410093]
GetHandleVerifier [0x00007FF6214BE7DD+3497293]
GetHandleVerifier [0x00007FF6214B2A73+3448803]
GetHandleVerifier [0x00007FF621237BBB+848171]
(No symbol) [0x00007FF6210E3C3F]
(No symbol) [0x00007FF6210DF6E4]
(No symbol) [0x00007FF6210DF87D]
(No symbol) [0x00007FF6210CED49]
BaseThreadInitThunk [0x00007FFF19B453E0+16]
RtlUserThreadStart [0x00007FFF1B0C485B+43]
Other rows get processed fine.
Here is the script I use to get it done:
bookings = driver.find_elements(By.XPATH, '//tr[contains(@class, "booking state0")]')
print(f"Number of bookings with state0: {len(bookings)}")
for index, booking in enumerate(bookings):
print(f"Booking {index}: {booking.get_attribute('outerHTML')}")
# Loop to process state0 bookings
for index, booking in enumerate(bookings):
try:
WebDriverWait(driver, 3).until(
EC.element_to_be_clickable(booking)
)
ActionChains(driver).move_to_element(booking).perform()
booking.click()
time.sleep(5)
# Wait for the check-in button to be available and click it
check_in_button = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, '//button[contains(@class, "btn-success")]'))
)
check_in_button.click()
time.sleep(3)
# Close the modal dialog after check-in
close_button = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable(
(By.XPATH, '//button[@type="button" and @class="btn btn-light" and @data-dismiss="modal"]')
)
)
Here I include the html I try to target:
<table class="table table-hover">
<tbody><tr>
<th class="text-center"><a href="?search_query=2866111&order_by=booking_id&order=ASC">Booking ID </a></th>
<th class="text-center"><a href="?search_query=2866111&order_by=room_name&order=ASC">Room</a></th>
<th class="text-center"><a href="?search_query=2866111&order_by=check_in_date&order=ASC">Check In</a></th>
<th class="text-center"><a href="?search_query=2866111&order_by=check_out_date&order=ASC">Check Out</a></th>
<th><a href="?search_query=2866111&order_by=customer_name&order=ASC">Customer</a></th>
</tr>
<tr class="booking state0" data-booking-id="2866111">
<td class="text-center">2866111</td>
<td class="text-center">V NR-1</td>
<td class="text-center">2025-01-09 15:00:00</td>
<td class="text-center">2025-01-10 12:00:00</td>
<td>ilvars F</td>
</tr>
</tbody></table>
I try to delay the first click and it did not solve the issue. Also tried use JavaScript to click but it did not work.
for booking in bookings:
try:
# Scroll into view and force the click using JavaScript
driver.execute_script("arguments[0].scrollIntoView(true);", booking)
driver.execute_script("arguments[0].click();", booking)
print("Clicked booking via JavaScript")
time.sleep(1)
except Exception as e:
print(f"Error clicking booking with JavaScript: {e}")
Also tried to click on element inside the row. What could be this issue?
本文标签: Selenium script runs fine only one timeStack Overflow
版权声明:本文标题:Selenium script runs fine only one time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736626992a1945695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论