Selenium Flashcards

1
Q

Find Element

A

driver.find_element(By.METHOD, locator)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Find Elements

A

driver.find_elements(By.METHOD, locator)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Wait for Presence of element

A

wait.until(EC.presence_of_element_located(By.CSS_SELECTOR, ‘.class’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Wait for visibility

A

wait.until(EC.visibility_of_element_located(By.CSS_SELECTOR, ‘.class’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Wait for Clickable

A

wait.until(EC.element_to_be_clickable(By.CSS_SELECTOR, ‘.class’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Action Chain

A
from selenium.webdriver.common.action_chains import ActionChains 

action = ActionChain(driver)
action.move_to_element(element)
action.perform()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Select

A
from selenium.webdriver.support.ui import Select

selector = Select(context.driver.find_element(*SORT_SELECTOR))
selector.select_by_index(2)
selector.select_by_visible_text('text')
selector.select_by_value('text')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Get text from an Element

A

element.text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Get value of CSS on element

A

element.value_of_css_property('text-decoration')

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Get attribute of HTML Element

A

element.get_attribute(‘alt’)`

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Reload Page

A

driver.refresh()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Set Up Driver

A
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='./env/bin/chromedriver')
driver = webdriver.Chrome(service=service)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Loop through list in assertion

A

assert any(dog[‘name’] == name for dog in data),

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Import By

A

from selenium.webdriver.common.by import By

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Import Expected Conditions

A

from selenium.webdriver.support import expected_conditions as EC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Setup Wait

A
from selenium.webdriver.support.ui import WebDriverWait

wait = WebDriverWait(driver, 10, 0.1)
17
Q

assert type

A

Note lack of Parethesis on dict

assert type(my_var) is dict
assert type(my_var) == str
assert type(my_var) is list
assert type(my_var) is int
18
Q

Capitalization

A
string.lower()
string.upper()
string.capitalize()
string.title()
19
Q

Get coordinates of a location

A
element.location['x']
element.location['y']
scroll_by_coord = 'window.scrollTo(%s,%s);' % (
            x,
            y
        )
20
Q

Selenium
Run Javascript

A

driver.execute_script(“arguments[0].value = ‘hello world’”, element)

21
Q

Selenium
CSS Selector for input html

A

(By.CSS_SELECTOR, 'input[placeholder="Last Name"]')

22
Q

Selenium
Assign active element

A

element = driver.switch_to.active_element

23
Q

Selenium Keys

A
from selenium.webdriver.common.keys import Keys

Keys.TAB
Keys.ARROW_LEFT
Keys.RETURN
Keys.SPACE
24
Q

Selenium XPATHs

A
(By.XPATH, '//*[@type="submit"]')

'//*[@aria-label="Go to Home"]'

//*[contains(text(), "example")]

(//*[@type="button"])[2]

//div[contains'
    '(@class, "some-class")]ancestor::div[contains'
    '(@class, "some-class")]/a