How to use get_element_attribute method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

get.py

Source:get.py Github

copy

Full Screen

1import pytest2from tests.support.asserts import assert_error, assert_success3from tests.support.inline import inline4def get_element_attribute(session, element, attr):5 return session.transport.send(6 "GET", "session/{session_id}/element/{element_id}/attribute/{attr}".format(7 session_id=session.session_id,8 element_id=element,9 attr=attr))10def test_no_browsing_context(session, closed_window):11 response = get_element_attribute(session, "foo", "id")12 assert_error(response, "no such window")13def test_element_not_found(session):14 # 13.2 Step 315 result = get_element_attribute(session, "foo", "id")16 assert_error(result, "no such element")17def test_element_stale(session):18 session.url = inline("<input id=foo>")19 element = session.find.css("input", all=False)20 session.refresh()21 result = get_element_attribute(session, element.id, "id")22 assert_error(result, "stale element reference")23def test_normal(session):24 # 13.2 Step 525 session.url = inline("<input type=checkbox>")26 element = session.find.css("input", all=False)27 result = get_element_attribute(session, element.id, "input")28 assert_success(result, None)29 # Check we are not returning the property which will have a different value30 assert session.execute_script("return document.querySelector('input').checked") is False31 element.click()32 assert True == session.execute_script("return document.querySelector('input').checked")33 result = get_element_attribute(session, element.id, "input")34 assert_success(result, None)35@pytest.mark.parametrize("tag,attrs", [36 ("audio", ["autoplay", "controls", "loop", "muted"]),37 ("button", ["autofocus", "disabled", "formnovalidate"]),38 ("details", ["open"]),39 ("dialog", ["open"]),40 ("fieldset", ["disabled"]),41 ("form", ["novalidate"]),42 ("iframe", ["allowfullscreen"]),43 ("img", ["ismap"]),44 ("input", ["autofocus", "checked", "disabled", "formnovalidate", "multiple", "readonly", "required"]),45 ("menuitem", ["checked", "default", "disabled"]),46 ("ol", ["reversed"]),47 ("optgroup", ["disabled"]),48 ("option", ["disabled", "selected"]),49 ("script", ["async", "defer"]),50 ("select", ["autofocus", "disabled", "multiple", "required"]),51 ("textarea", ["autofocus", "disabled", "readonly", "required"]),52 ("track", ["default"]),53 ("video", ["autoplay", "controls", "loop", "muted"])54])55def test_boolean_attribute(session, tag, attrs):56 for attr in attrs:57 session.url = inline("<{0} {1}>".format(tag, attr))58 element = session.find.css(tag, all=False)59 result = get_element_attribute(session, element.id, attr)60 assert_success(result, "true")61def test_global_boolean_attributes(session):62 session.url = inline("<p hidden>foo")63 element = session.find.css("p", all=False)64 result = get_element_attribute(session, element.id, "hidden")65 assert_success(result, "true")66 session.url = inline("<p>foo")67 element = session.find.css("p", all=False)68 result = get_element_attribute(session, element.id, "hidden")69 assert_success(result, None)70 session.url = inline("<p itemscope>foo")71 element = session.find.css("p", all=False)72 result = get_element_attribute(session, element.id, "itemscope")73 assert_success(result, "true")74 session.url = inline("<p>foo")75 element = session.find.css("p", all=False)76 result = get_element_attribute(session, element.id, "itemscope")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful