|
4 | 4 | with SB(uc=True, test=True, ad_block=True) as sb:
|
5 | 5 | url = "https://chatgpt.com/"
|
6 | 6 | sb.activate_cdp_mode(url)
|
| 7 | + sb.sleep(1) |
| 8 | + sb.click_if_visible('button[aria-label="Close dialog"]') |
7 | 9 | query = "Compare Playwright to SeleniumBase in under 178 words"
|
8 | 10 | sb.press_keys("#prompt-textarea", query)
|
9 | 11 | sb.click('button[data-testid="send-button"]')
|
10 | 12 | print('*** Input for ChatGPT: ***\n"%s"' % query)
|
| 13 | + sb.sleep(3) |
11 | 14 | with suppress(Exception):
|
12 | | - # The "Send" button reappears when ChatGPT is done typing a response |
13 | | - sb.wait_for_element('button[data-testid="send-button"]', timeout=22) |
| 15 | + # The "Stop" button disappears when ChatGPT is done typing a response |
| 16 | + sb.wait_for_element_not_visible( |
| 17 | + 'button[data-testid="stop-button"]', timeout=20 |
| 18 | + ) |
14 | 19 | chat = sb.find_element('[data-message-author-role="assistant"] .markdown')
|
15 | 20 | soup = sb.get_beautiful_soup(chat.get_html()).get_text("\n").strip()
|
16 | 21 | print("*** Response from ChatGPT: ***\n%s" % soup.replace("\n:", ":"))
|
|
0 commit comments