This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathactions.py
executable file
·50 lines (39 loc) · 1.81 KB
/
actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from robocorp import browser
from robocorp.actions import action
from typing import Annotated
from pydantic import BaseModel, Field
class Prospect(BaseModel):
first_name: Annotated[str, Field(description="User's first name")]
last_name: Annotated[str, Field(description="User's last name")]
company_name: Annotated[str, Field(description="Company name")]
email: Annotated[str, Field(description="User's email address")]
phone: Annotated[str, Field(description="User's phone number, use international format.")]
@action(is_consequential="False")
def fill_form_with_user_data(data: Prospect) -> str:
"""
Fill in Robocorp Contact form with user details using a browser.
Args:
data: A person object that will be entered to the Robocorp Contact form.
Returns:
str: True if operation was success, and False if it failed, including an error message.
"""
browser.configure(
browser_engine="chromium",
screenshot="only-on-failure",
headless=False,
# slowmo=100
)
page = browser.goto("https://robocorp.com/contact-us-internal-test")
page.locator("[name=firstname]").fill(data.first_name)
page.locator("[name=lastname]").fill(data.last_name)
page.locator("[name=email]").fill(data.email)
page.locator("[name=company]").fill(data.company_name)
page.locator("[name=phone]").fill(data.phone)
page.locator("[name=how_can_our_team_help_you_]").select_option("Get a product demo")
page.locator("xpath=//input[@value='Get in Touch']").click()
elements = page.locator("//label[(contains(text(), 'Please complete this required field.')) or (contains(text(), 'Email must be formatted correctly.'))]")
count = elements.count()
if count > 0:
return "False: data is invalid."
else:
return "True"