0% found this document useful (0 votes)
7 views

Syntax Locator

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Syntax Locator

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Basic Locators

Locator
Syntax Example Selenium syntax Example
Type
Xpath //tagname[attribute=value] "//input[@name='email']" driver.find_element_by_xpath("//input[@name='email']")
Css
tagname[attribute=value] "input[name='email']" driver.find_element_by_css_selector("input[name='email']")
selector
ID No syntax "id" driver.find_element_by_id("exampleFormControlSelect1")

Name No syntax "name" driver.find_element_by_name("name")

Class name No syntax "class-name" driver.find_element_by_class_name("btn-success")

Link text No syntax "link-text" driver.find_element_by_link_text("Genealogies")


Partial link
No syntax "partialtext" driver.find_element_by_partial_link_text("partialtext")
text
Tag name No syntax "tag-name" driver.find_element_by_tag_name("span")

Customized XPATH Locator Without Tag Name

Replace tag name with asterisk (*) sign


Syntax: //*[attribute=value]
Example: //*[@name = ‘email’]

Customized CSS Selector Syntax Without Tag Name


Remove tag name
Syntax: [attribute=value]
Example: [class*=‘alert-succes’]

Generating XPATH based on text

Syntax: //tagname[contains(text(), ‘actual-text’)]


Example: //span[contains(text(),'Users Info')]

Creating XPATH by traversing tags

Syntax: ParentTag/ChildTag
Example: //div[@class='product-action']/button

Creating a CSS Selector by traversing to nth child

Syntax: Tagname:nth-child(x)
Example: div:nth-child(1)

Select Parent Locator from Child using XPATH

Syntax XPATH/parent::tagname
Example: //*[title="test"]/parent::div

Generating CSS Selector from Tag and Class Name

Replace spaces with period(.) to use more than one class name
Syntax: Tagname.ClassName
Example: input.search-keyword
import subprocess
import win32api
import win32com.client
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
import time

from selenium.webdriver.support.wait import WebDriverWait

global driver
driver = webdriver.Chrome(executable_path="D:\\chromedriver_win32\\chromedriver.exe")
driver.implicitly_wait(3)
driver.maximize_window()
global wait
wait = WebDriverWait(driver, 10)

# login to CPC with MPass

def test_login():
driver.get("https://preproductie.sfs.md/ro/cabinetul-contribuabilului/login")
driver.find_element(By.XPATH, "//a[@class='alert alert-dark d-block text-center mpass-card']").click()
driver.find_element(By.XPATH, "//div[@class='well-sm btn-default']").click()
driver.find_element(By.CSS_SELECTOR, "button[class='list-group-item']").click()
time.sleep(2)

# click on signature windows pop-up

def test_win_mpass():
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("1234567890")
shell.SendKeys("{ENTER}")

wait.until(expected_conditions.presence_of_element_located((By.ID, "dropdownLang")))

# Select a company

def test_list_companies():
driver.find_element(By.ID, "dropdownLang").click()
driver.find_element(By.XPATH,
"//header/div[1]/div[1]/div[1]/div[3]/div[1]/div[1]/ul[1]/li[1]/a[1]").click()
driver.find_element(By.XPATH, "(//div[@class='title-sidebar txt_14'])[2]").click()

wait.until(expected_conditions.presence_of_element_located(
(By.XPATH, "(//a[@class='btn_company-default btn-company-name btn_dark-blue'])[5]")))
driver.find_element(By.XPATH, "(//a[@class='btn_company-default btn-company-name btn_dark-blue'])
[5]").click()

def test_select_service_rea(): # SELECT REA


wait.until(expected_conditions.presence_of_element_located(
(By.XPATH, "(//div[@class='block_top-promoternus services'])[18]")))

element = driver.find_element(By.XPATH, "//span[contains(text(),'Registru electronic al angajatilor


(REA)')]")
driver.execute_script("arguments[0].click();", element)
# change active browser window

time.sleep(7)
windows_opened = driver.window_handles

driver.switch_to.window(windows_opened[1])

def test_create_state(): #Create a basic state


wait.until(expected_conditions.presence_of_element_located(
(By.XPATH, "(//div[@class='block_top-promoternus services'])[18]")))

# def test_teardown():
# driver.close()
# driver.quit()
# print("Test Completed")

You might also like