Hello,
I’m wondering how to use a browser window - opened from within my library - in my project’s code.
I created a library that logs in and out of a website. I imported that library into my project and can run those two keywords without issues. Now, in between those two keywoards, I want to continue developing the project, using that already opened window. However, the lines in between the log in and out complain that Error: Could not find active page
. I’ve tried reading the browser catalog and browser id in order to switch / attach to it, but both appear as empty lists. I’ve also modified my Log In to return the opened browser, but no luck. It’s like my project has no knowledge or visibility of the browser / context from my library.
MyLib.py:
from RPA.Browser.Playwright import Playwright
class MyLib:
PW = Playwright()
def log_in(self, username, password):
MyLib.PW.new_browser(headless=False)
MyLib.PW.new_page(<url>)
MyLib.PW.type_text("id=login_id", username)
MyLib.PW.press_keys("id=login_id", "Enter")
MyLib.type_text("id=password", password)
MyLib.PW.press_keys("id=password", "Enter")
return MyLib.PW
def log_out(self):
MyLib.PW.click("id=sign_out")
My project:
*** Settings ***
Documentation Template robot main suite.
Library RPA.Browser.Playwright
Library MyLib
*** Tasks ***
Log In Click and Log Out
${browser}= Log In <username> <password> # does not appear to return the browser
${browser_catalog}= Get Browser Catalog # empty list []
${browser_ids}= Get Browser Ids # empty list []
Click id=some_id # Error: Could not find active page
Log Out
Is MyLib structured correctly? Is the issue in my project?
Thanks