SeleniumBase
SeleniumBase copied to clipboard
Use this: (Don't use `uc_click()` if it takes you to a screen with a pop-up alert.)
Use this: (Don't use `uc_click()` if it takes you to a screen with a pop-up alert.)
from seleniumbase import SB
with SB(uc=True, incognito=True) as sb:
url = 'https://tixcraft.com/ticket/ticket/24_lss/16628/1/11'
sb.driver.uc_open_with_reconnect(url, reconnect_time=5)
sb.send_keys('//input[@id="TicketForm_verifyCode"]', 'afnd')
sb.select_option_by_text("#TicketForm_ticketPrice_01", '1')
sb.driver.uc_click('input#TicketForm_agree')
sb.driver.click('button[type="submit"]')
sb.sleep(2)
sb.accept_alert()
sb.sleep(5)
Originally posted by @mdmintz in https://github.com/seleniumbase/SeleniumBase/issues/2662#issuecomment-2038876243
Hi @mdmintz ,
I have a use case where it requires using uc_click on the form submit button as the driver is detectable after submission. However, this form takes me to a page with an alert to be dismissed before the rest of the page loads.
Is there a solution?
Here is an example:
from seleniumbase import SB
with SB(uc=True) as sb:
sb.open("https://form-page.tiiny.site")
# Does not work - Code is stuck here as it waits for page to complete loading
sb.uc_click("input", timeout=2, reconnect_time=2)
# Works - Does not wait for page to complete loading, but I need uc_click
# sb.click("input")
sb.dismiss_alert()
print(sb.get_page_source())
There is a solution. The code below works on seleniumbase 4.26.4 (or newer) after installing pyautogui:
import pyautogui
from seleniumbase import SB
with SB(uc=True) as sb:
sb.open("https://form-page.tiiny.site")
sb.uc_click("input", timeout=2, reconnect_time="disconnect")
sb.sleep(1)
pyautogui.press("\n")
sb.sleep(1)
sb.reconnect()
print(sb.get_page_source())
@mdmintz Thanks, this works! Did not know that reconnect_time="disconnect" existed.
Do you also have a solution if I need this with headless seleniumbase?
For non UC Mode headless seleniumbase, you wouldn't need pyautogui at all. But for maximum stealth in UC Mode, use a headed browser.
Got it, thank you for the help!