-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import asyncio | ||
import os | ||
|
||
from locatr import LlmProvider, LlmSettings, Locatr, LocatrCdpSettings | ||
|
||
llm_settings = LlmSettings( | ||
llm_provider=LlmProvider.OPENAI, | ||
llm_api_key=os.environ.get("LLM_API_KEY"), | ||
model_name=os.environ.get("LLM_MODEL"), | ||
reranker_api_key=os.environ.get("COHERE_API_KEY"), | ||
) | ||
|
||
# there is already a page opened for url: https://example.com/ | ||
locatr_settings_cdp = LocatrCdpSettings( | ||
llm_settings=llm_settings, | ||
cdp_url="http://localhost:9222", | ||
) | ||
|
||
|
||
async def main(): | ||
selenium_locatr = Locatr(locatr_settings_cdp) | ||
print( | ||
await selenium_locatr.get_locatr_async("Link to 'More information...'") | ||
) | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import time | ||
|
||
from playwright.sync_api import sync_playwright | ||
|
||
from locatr import LlmProvider, LlmSettings, Locatr, LocatrCdpSettings | ||
|
||
|
||
def setup_locatr() -> Locatr: | ||
llm_settings = LlmSettings( | ||
llm_provider=LlmProvider.OPENAI, | ||
llm_api_key=os.environ.get("LLM_API_KEY"), | ||
model_name=os.environ.get("LLM_MODEL"), | ||
reranker_api_key=os.environ.get("COHERE_API_KEY"), | ||
) | ||
locatr_settings_cdp = LocatrCdpSettings( | ||
llm_settings=llm_settings, | ||
cdp_url="http://localhost:9222", | ||
) | ||
return Locatr(locatr_settings_cdp) | ||
|
||
|
||
def main(cdp_locatr: Locatr): | ||
with sync_playwright() as p: | ||
browser = p.chromium.launch( | ||
headless=False, args=["--remote-debugging-port=9222"] | ||
) | ||
page = browser.new_page() | ||
page.goto("https://store.steampowered.com/") | ||
time.sleep(5) | ||
|
||
search_bar_selector = cdp_locatr.get_locatr( | ||
"Search input bar on the steam store." | ||
) | ||
|
||
search_barch_locatr = page.locator(search_bar_selector) | ||
search_barch_locatr.first.fill("Counter Strike 2") | ||
search_barch_locatr.first.press("Enter") | ||
|
||
time.sleep(5) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(setup_locatr()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import time | ||
|
||
from selenium import webdriver | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.by import By | ||
|
||
from locatr import LlmProvider, LlmSettings, Locatr, LocatrSeleniumSettings | ||
|
||
|
||
def setup_locatr(selenium_url: str, selenium_session_id: str) -> Locatr: | ||
llm_settings = LlmSettings( | ||
llm_provider=LlmProvider.OPENAI, | ||
llm_api_key=os.environ.get("LLM_API_KEY"), | ||
model_name=os.environ.get("LLM_MODEL"), | ||
reranker_api_key=os.environ.get("COHERE_API_KEY"), | ||
) | ||
locatr_settings_cdp = LocatrSeleniumSettings( | ||
llm_settings=llm_settings, | ||
selenium_url=selenium_url, | ||
selenium_session_id=selenium_session_id, | ||
) | ||
return Locatr(locatr_settings_cdp) | ||
|
||
|
||
def main(): | ||
opts = Options() | ||
dr = webdriver.Remote( | ||
command_executor="http://127.0.0.1:4444/wd/hub", options=opts | ||
) | ||
try: | ||
dr.get("https://hub.docker.com/") | ||
time.sleep(5) | ||
locatr = setup_locatr( | ||
"http://127.0.0.1:4444/wd/hub", str(dr.session_id) | ||
) | ||
search_bar_path = locatr.get_locatr("Search Docker Hub input field") | ||
element = dr.find_element(By.CSS_SELECTOR, search_bar_path) | ||
element.send_keys("Python") | ||
element.send_keys("Enter") | ||
time.sleep(2) | ||
print(dr.title) | ||
finally: | ||
dr.quit() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |