SeleniumBase/examples/test_parse_soup.py

37 lines
1.6 KiB
Python
Raw Normal View History

2020-12-04 12:31:49 +08:00
import re
from seleniumbase import BaseCase
2023-02-03 13:27:36 +08:00
BaseCase.main(__name__, __file__)
2020-12-04 12:31:49 +08:00
2021-03-11 06:27:52 +08:00
class SoupParsingTests(BaseCase):
2020-12-04 12:31:49 +08:00
def click_menu_item(self, text):
# Use BeautifulSoup to parse the selector ID from element text.
# Then click on the element with the ID.
# (This is useful when the selector ID is auto-generated.)
pattern = re.compile(text)
soup = self.get_beautiful_soup()
2022-04-10 22:51:12 +08:00
the_id = soup.find(string=pattern).parent.parent.attrs["id"]
2020-12-04 12:31:49 +08:00
self.click("#%s" % the_id)
2023-02-18 12:55:54 +08:00
def test_beautiful_soup_parsing(self):
2020-12-04 12:31:49 +08:00
self.open("https://seleniumbase.io/tinymce/")
self.wait_for_element("div.mce-container-body")
self.click_menu_item("File")
self.click_menu_item("New document")
self.click_menu_item("Paragraph")
self.click_menu_item("Heading 2")
self.switch_to_frame("iframe")
self.add_text("#tinymce", "Automate anything with SeleniumBase!\n")
self.switch_to_default_content()
2021-05-06 09:06:24 +08:00
self.click("button i.mce-i-image")
2020-12-04 12:31:49 +08:00
self.type('input[aria-label="Width"].mce-textbox', "300")
2022-12-24 11:25:45 +08:00
image_url = "https://seleniumbase.github.io/img/sb_logo_10.png"
2020-12-04 12:31:49 +08:00
self.type("input.mce-textbox", image_url + "\n")
2023-01-01 05:43:19 +08:00
with self.frame_switch("iframe"):
self.click("h2")
self.post_message("Automate anything with SeleniumBase!")
2020-12-04 12:31:49 +08:00
self.click_menu_item("File")
self.click_menu_item("Preview")
2023-01-01 05:43:19 +08:00
with self.frame_switch('iframe[sandbox="allow-scripts"]'):
self.post_message("Learn SeleniumBase Today!")