How to use test_find_element method in pytractor

Best Python code snippet using pytractor_python

test_selenium.py

Source:test_selenium.py Github

copy

Full Screen

...10 print 'requires selenium Python bindings; pip install selenium'11 raise12from selenium_proxy import SeleniumProxy13from testserver import TestServer14def test_find_element(driver, fn):15 """ Test a find_element_by_FOO method of both the webdriver16 and the WebElement class. The former will return a WebElement which17 should have a method of the same name, which should also return18 a WebElement.19 """20 element = getattr(driver, fn)('foo')21 assert(isinstance(element, WebElement))22 assert(element.id == TestServer.TEST_FIND_ELEMENT)23 child = getattr(element, fn)('foo')24 assert(isinstance(child, WebElement))25 assert(child.id == TestServer.TEST_FIND_ELEMENT)26def test_find_elements(driver, fn):27 """ Test a find_elements_by_FOO method of both the webdriver28 and the WebElement class. The former will return a list of 29 WebElements, each of which should have a method of the same name,30 and which in should turn should also return a list of WebElements.31 """32 elements = getattr(driver, fn)('foo')33 # elements should be a list34 assert(isinstance(elements, list))35 # elements should match the TEST_FIND_ELEMENTS list36 assert(map(lambda x: x.id, elements) == TestServer.TEST_FIND_ELEMENTS)37 # Each member of elements should be a WebElement that has the same38 # method, which should in turn return a list of WebElements when called.39 for element in elements:40 assert(isinstance(element, WebElement))41 children = getattr(element, fn)('foo')42 assert(isinstance(children, list))43 assert(map(lambda x: x.id, children) == TestServer.TEST_FIND_ELEMENTS)44 assert(len(filter(lambda x: not isinstance(x, WebElement), children)) == 0)45if __name__ == '__main__':46 # start the test server on port 262647 server = TestServer(2626)48 thread = threading.Thread(target=server.run)49 thread.daemon = True50 thread.start()51 # Start the selenium proxy on port 4444, connecting to the test server52 # on port 2626.53 proxy = SeleniumProxy('127.0.0.1', 2626, proxy_port=4444)54 proxy_thread = threading.Thread(target=proxy.start)55 proxy_thread.daemon = True56 proxy_thread.start()57 # invoke selenium commands as tests58 driver = webdriver.Remote(command_executor='http://127.0.0.1:4444',59 desired_capabilities=webdriver.DesiredCapabilities.FIREFOX)60 assert(driver)61 # test navigation methods62 driver.get(TestServer.TEST_URL)63 assert(driver.current_url == TestServer.TEST_URL)64 driver.back()65 driver.forward()66 driver.refresh()67 # test script methods68 driver.set_script_timeout(10) # in selenium the number is in seconds69 driver.implicitly_wait(10) # ditto70 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_script(TestServer.TEST_EXECUTE_SCRIPT))71 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_script(TestServer.TEST_EXECUTE_SCRIPT,72 TestServer.TEST_EXECUTE_SCRIPT_ARGS))73 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_async_script(TestServer.TEST_EXECUTE_SCRIPT))74 assert(TestServer.TEST_EXECUTE_RETURN_VALUE == driver.execute_async_script(TestServer.TEST_EXECUTE_SCRIPT,75 TestServer.TEST_EXECUTE_SCRIPT_ARGS))76 # test all the find_element_by_FOO methods77 test_find_element(driver, 'find_element_by_name')78 test_find_element(driver, 'find_element_by_id')79 test_find_element(driver, 'find_element_by_xpath')80 test_find_element(driver, 'find_element_by_link_text')81 test_find_element(driver, 'find_element_by_partial_link_text')82 test_find_element(driver, 'find_element_by_tag_name')83 test_find_element(driver, 'find_element_by_class_name')84 test_find_element(driver, 'find_element_by_css_selector')85 # test all the find_elements_by_FOO methods86 test_find_elements(driver, 'find_elements_by_name')87 test_find_elements(driver, 'find_elements_by_id')88 test_find_elements(driver, 'find_elements_by_xpath')89 test_find_elements(driver, 'find_elements_by_link_text')90 test_find_elements(driver, 'find_elements_by_partial_link_text')91 test_find_elements(driver, 'find_elements_by_tag_name')92 test_find_elements(driver, 'find_elements_by_class_name')93 test_find_elements(driver, 'find_elements_by_css_selector')94 # test WebElement methods95 element = driver.find_element_by_name('foo')96 element.click()97 assert(element.text == TestServer.TEST_GET_TEXT)98 element.send_keys('Mozilla Firefox')...

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 pytractor 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