How to use frame_locator method in Playwright Python

Best Python code snippet using playwright-python

badminton.py

Source:badminton.py Github

copy

Full Screen

...55 ):56 page = context.new_page()57 # badminton workflow url58 page.goto("https://oa.shanghaitech.edu.cn/workflow/request/AddRequest.jsp?workflowid=14862")59 page.frame_locator('iframe[name="bodyiframe"]').locator("#field31898_0").wait_for()60 frame0 = page.frame("bodyiframe")61 frame0.locator("#field31898_0").fill(Class_info.list2d_jieyongren[0][0])62 frame0.locator("#field31899_0").fill(Class_info.list2d_jieyongren[0][1])63 frame0.locator("#field31898_1").fill(Class_info.list2d_jieyongren[1][0])64 frame0.locator("#field31899_1").fill(Class_info.list2d_jieyongren[1][1])65 # 场馆类型66 frame0.select_option('select#field32340',"4")67 # 使用日期68 frame0.locator('button#field31901browser').click()69 frame1 = frame0.frame_locator('[id="_my97DP"] iframe')70 frame1.locator('[onclick="day_Click('+Class_info.str_date+');"]').click()71 # 使用时间72 frame0.locator('button#field31902_browserbtn').click()73 frame2 = page.frame_locator('iframe[src="/systeminfo/BrowserMain.jsp?url=/interface/CommonBrowser.jsp?type=browser.sysjd|31902"]').frame_locator('iframe[name="main"]')74 frame2.locator('input[name="con31860_value"]').fill(Class_info.str_time)75 frame2.locator('input[id="btnsearch"]').click()76 frame2.locator('td:has-text("'+Class_info.str_time+'")').click()77 # 使用场地78 frame0.click('button#field31883_browserbtn')79 frame3 = page.frame_locator('iframe[src="/systeminfo/BrowserMain.jsp?url=/formmode/tree/treebrowser/CustomTreeBrowser.jsp%3Fderecorderindex%3D%26type%3D63_256_256%26selectedids%3D"]').frame_locator('iframe[id="main"]').frame_locator('iframe[id="tabcontentframe"]')80 # 场馆使用情况表81 # 体育馆82 # 室内羽毛球场83 for int_i in range(3):84 ico = frame3.locator("#CustomTree_"+str(int_i+1)+"_ico")85 button = ico.get_attribute('class')86 if (button == 'button ico_close' ):87 ico.click()88 elif ( button == 'button ico_open' ):89 pass90 elif ( button == 'button ico_docu' ):91 print('此时间段申请人已满!')92 return93 # 羽毛球场地1号...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...38 page.goto("http://43.248.49.97/")39 time.sleep(1)40 pyautogui.hotkey('win', 'up')41 # Select 342 page.frame_locator("iframe").nth(1).locator("select[name=\"year\"]").select_option("2021")43 page.wait_for_timeout(100)44 page.frame_locator("iframe").nth(1).locator("select[name=\"year\"]").click()45 page.wait_for_timeout(100)46 page.frame_locator("iframe").nth(1).locator("select[name=\"startMonth\"]").select_option("1")47 page.wait_for_timeout(100)48 page.frame_locator("iframe").nth(1).locator("select[name=\"startMonth\"]").click()49 page.wait_for_timeout(100)50 page.frame_locator("iframe").nth(1).locator("select[name=\"endMonth\"]").select_option("3")51 page.wait_for_timeout(100)52 page.frame_locator("iframe").nth(1).locator("select[name=\"endMonth\"]").click()53 page.wait_for_timeout(100)54 # Select CODE_TS55 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField1\"]").select_option("CODE_TS")56 page.wait_for_timeout(100)57 # Click input[name="outerValue1"]58 page.frame_locator("iframe").nth(1).locator("input[name=\"outerValue1\"]").click()59 page.wait_for_timeout(100)60 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField2\"]").select_option("ORIGIN_COUNTRY")61 page.wait_for_timeout(100)62 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField2\"]").click()63 # Select TRADE_MODE64 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField3\"]").select_option("TRADE_MODE")65 page.wait_for_timeout(100)66 # Select TRADE_CO_PORT67 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField3\"]").click()68 page.wait_for_timeout(100)69 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField4\"]").select_option("TRADE_CO_PORT")70 # Fill input[name="outerValue1"]71 page.wait_for_timeout(100)72 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField4\"]").click()73 page.wait_for_timeout(100)74 page.frame_locator("iframe").nth(1).locator("input[name=\"outerValue1\"]").fill(f"{key}")75 page.wait_for_timeout(100)76 # Click text=查询77 page.frame_locator("iframe").nth(1).locator("text=查询").click()78 page.wait_for_timeout(300)79 # Click text=确定80 page.frame_locator("iframe").nth(1).locator("text=确定").click()81 page.wait_for_timeout(2000)82 page.screenshot(path='page.png', full_page=True)83 print('=== screenshot page ==')84 crop_image('page.png')85 time.sleep(1)86 mouse_action(mark_edge('1.jpg'))87 try:88 page.frame_locator("iframe").nth(1).frame_locator("iframe[name=\"layui-layer-iframe2\"]").locator(89 "text=确定").click()90 except:91 page.screenshot(path='page.png', full_page=True)92 print('=== screenshot page ==')93 crop_image('page.png')94 time.sleep(1)95 mouse_action(mark_edge('1.jpg'))96 # Close page97 page.wait_for_timeout(300)98 # Click text=确定99 page.frame_locator("iframe").nth(1).frame_locator("iframe[name=\"layui-layer-iframe2\"]").locator("text=确定").click()100 page.wait_for_timeout(200)101 # Click text=返回设置102 page.frame_locator("iframe").nth(1).locator("text=返回设置").click()103 page.wait_for_timeout(500)104 page.close()105 # ---------------------106 # context.close()107 # browser.close()108def mouse_action(x: int):109 pyautogui.moveTo(919, 675)110 pyautogui.click(919, 675)111 time.sleep(random.uniform(1, 2))112 pyautogui.dragTo(980 + x, 675, duration=random.uniform(1, 2))113 time.sleep(random.uniform(1, 2))114def mark_edge(image_path: str):115 p = cv2.imread(image_path)116 hsv = cv2.cvtColor(p, cv2.COLOR_BGR2HSV)...

Full Screen

Full Screen

demo1.py

Source:demo1.py Github

copy

Full Screen

...30 # 0× click31 page.locator("html").click()32 page.wait_for_timeout(1000)33 # Select 334 page.frame_locator("iframe").nth(1).locator("select[name=\"year\"]").select_option("2021")35 page.wait_for_timeout(200)36 page.frame_locator("iframe").nth(1).locator("select[name=\"year\"]").click()37 page.wait_for_timeout(200)38 page.frame_locator("iframe").nth(1).locator("select[name=\"startMonth\"]").select_option("1")39 page.wait_for_timeout(200)40 page.frame_locator("iframe").nth(1).locator("select[name=\"startMonth\"]").click()41 page.wait_for_timeout(200)42 page.frame_locator("iframe").nth(1).locator("select[name=\"endMonth\"]").select_option("3")43 page.wait_for_timeout(200)44 page.frame_locator("iframe").nth(1).locator("select[name=\"endMonth\"]").click()45 page.wait_for_timeout(200)46 # Select CODE_TS47 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField1\"]").select_option("CODE_TS")48 page.wait_for_timeout(200)49 # Click input[name="outerValue1"]50 page.frame_locator("iframe").nth(1).locator("input[name=\"outerValue1\"]").click()51 page.wait_for_timeout(200)52 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField2\"]").select_option("ORIGIN_COUNTRY")53 page.wait_for_timeout(200)54 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField2\"]").click()55 # Select TRADE_MODE56 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField3\"]").select_option("TRADE_MODE")57 page.wait_for_timeout(200)58 # Select TRADE_CO_PORT59 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField3\"]").click()60 page.wait_for_timeout(200)61 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField4\"]").select_option("TRADE_CO_PORT")62 # Fill input[name="outerValue1"]63 page.wait_for_timeout(200)64 page.frame_locator("iframe").nth(1).locator("select[name=\"outerField4\"]").click()65 page.wait_for_timeout(200)66 page.frame_locator("iframe").nth(1).locator("input[name=\"outerValue1\"]").fill(f"{key}")67 page.wait_for_timeout(300)68 # Click text=查询69 page.frame_locator("iframe").nth(1).locator("text=查询").click()70 page.wait_for_timeout(300)71 # Click text=确定72 page.frame_locator("iframe").nth(1).locator("text=确定").click()73 page.wait_for_timeout(2000)74 page.screenshot(path='page.png', full_page=True)75 print('=== screenshot page ==')76 image_action('page.png')77 time.sleep(1)78 mouse_action(mark_edge('1.jpg'))79 # Close page80 page.wait_for_timeout(300)81 page.frame_locator("iframe").first.frame_locator("iframe[name=\"layui-layer-iframe2\"]").locator(82 "text=确定").click()83 page.wait_for_timeout(500)84 page.close()85 # ---------------------86 context.close()87 browser.close()88# with sync_playwright() as playwright:89# run(playwright, '04063000')...

Full Screen

Full Screen

get_element_module.py

Source:get_element_module.py Github

copy

Full Screen

1from JDI.core.settings.jdi_settings import JDISettings2class GetElementModule(object):3 FAILED_TO_FIND_ELEMENT_MESSAGE = "Can't find Element '{0}' during seconds"4 FIND_TO_MUCH_ELEMENTS_MESSAGE = "Find %s elements instead of one for Element '%s' during %s seconds"5 def __init__(self, by_locator=None, element=None):6 self.by_locator = by_locator7 self.element = element8 self.web_element = None9 self.web_elements = []10 self.frame_locator = None11 # self.logger = JDISettings.get_logger()12 def get_element(self):13 #self.logger.debug("Get Web Element: " + str(self.element))14 # element = self.web_element if self.web_element is not None else self.__get_element_action()15 # if self.web_element is None:16 self.web_element = self.__get_element_action()17 element = self.web_element18 # self.logger.debug("One Element found")19 return element20 def get_elements(self):21 result = self.__search_elements()22 if result is None:23 raise Exception("Can't get Web Elements")24 return result25 def __get_element_action(self):26 result = self.__get_one_or_more_elements()27 if len(result) == 0:28 raise Exception(GetElementModule.FAILED_TO_FIND_ELEMENT_MESSAGE.format(self.element))29 elif len(result) == 1:30 return result[0]31 elif len(result) > 1:32 result = [element for element in result if element.is_displayed()]33 return result[0]34 else:35 raise Exception(GetElementModule.FIND_TO_MUCH_ELEMENTS_MESSAGE % len(result), self.element)36 def __get_one_or_more_elements(self):37 return self.web_elements if self.web_elements else self.__search_elements()38 def __search_elements(self):39 # TODO: containsRoot40 locator = self.by_locator41 search_context = self.get_search_context(self.element.parent)42 if search_context is None:43 search_context = self.get_driver()44 # if self.frame_locator is not None:45 # self.get_driver().switch_to().frame(self.get_driver().find_element(self.frame_locator))46 return search_context.find_elements(locator[0], locator[1])47 @staticmethod48 def get_driver():49 return JDISettings.get_driver_factory().get_driver()50 def get_search_context(self, b_element):51 from JDI.web.selenium.elements.composite.web_site import WebSite52 try:53 if issubclass(type(self.element.parent), WebSite) or issubclass(self.element.parent, WebSite):54 return None55 except: pass56 if self.element.parent is not None:57 locator = b_element.avatar.by_locator58 if locator is None:59 return None60 driver = self.get_driver()61 if b_element.avatar.frame_locator is not None:62 self.switch_to_last_opened_window()63 res = driver.find_element(locator[0], locator[1])64 driver.switch_to_frame(b_element.avatar.frame_locator[1])65 return driver66 return driver.find_element(locator[0], locator[1])67 def switch_to_last_opened_window(self):...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful