How to use find_visible_elements method in SeleniumBase

Best Python code snippet using SeleniumBase

elements_base.py

Source:elements_base.py Github

copy

Full Screen

...3from seleniumbase import BaseCase4class MyElements(BaseCase):5 def elements_click(self,dr, selectory):6 """探针卸载获得的class都是第一个7 #elements=dr.find_visible_elements(".ivu-btn.ivu-btn-primary.ivu-btn-large")#确定8 """9 try:10 time.sleep(0.5)11 elements = dr.find_visible_elements(selectory[0]) # 确定12 if len(elements) == 1: # 如果可见元素list的长度等于113 time.sleep(0.5)14 elements[0].click()15 else:16 element = elements[selectory[1]]17 element.click()18 except IndexError:19 elements = dr.find_elements(selectory[0]) # 确定20 if len(elements) == 1: # 如果可见元素list的长度等于121 elements[0].click()22 else:23 element = elements[selectory[1]]24 element.click()25 except ElementNotInteractableException:26 time.sleep(2)27 elements = dr.find_elements(selectory[0]) # 确定28 if len(elements) == 1: # 如果可见元素list的长度等于129 elements[0].click()30 else:31 element = elements[selectory[1]]32 element.click()33 # if len(elements) > selectory[1] and len(elements)!=1: #list的长度大于预期值34 # time.sleep(1)35 # if len(elements) <= selectory[1] and len(elements)!=1: #list小于等于预期值。36 # elements = dr.find_elements(selectory[0])37 #38 # return 039 # if len(elements) <= selectory[1] and len(elements) != 1: # list小于等于预期值。40 # elements = dr.find_elements(selectory[0])41 # element = elements[selectory[1]]42 # element.click()43 # return 044 #except ElementNotInteractableException:45 def elements_text_update(self,dr, selectory, msg):46 """探针卸载获得的class都是第一个47 #elements=dr.find_visible_elements(".ivu-btn.ivu-btn-primary.ivu-btn-large")#确定48 """49 # print(selectory)50 try:51 elements = dr.find_visible_elements(selectory[0]) # 确定52 if len(elements) == 1: #如果可见元素list的长度等于153 element = elements[0]54 element.clear()55 element.send_keys(msg)56 if len(elements) >= selectory[1] and len(elements)!=1: #如果可见元素list的长度大于预期值57 element = elements[selectory[1]]58 element.clear()59 element.send_keys(msg)60 if len(elements) < selectory[1] and len(elements)!=1: #如果可见元素大于1,小于预期值。61 elements = dr.find_elements(selectory[0])62 element = elements[selectory[1]]63 element.clear()64 element.send_keys(msg)65 except ElementNotVisibleException:...

Full Screen

Full Screen

main_page.py

Source:main_page.py Github

copy

Full Screen

...17 add_button = BrowserHelper.find_clickable_element(self.driver, *MainPageLoctors.ADD_TASK_BUTTON)18 add_button.click()19 20 def go_to_edit_task(self):21 task_titles = BrowserHelper.find_visible_elements(self.driver, *MainPageLoctors.TASK_TITLES)22 first_title = task_titles[0]23 first_title.click()24 25 def open_navigation_bar(self):26 actions = TouchAction(self.driver)27 actions.long_press(None, 50, 800).move_to(None, 800, 800).release().perform()28 29 def should_be_correct_first_title_name(self):30 task_titles = BrowserHelper.find_visible_elements(self.driver, *MainPageLoctors.TASK_TITLES)31 first_title = task_titles[0]32 assert f"{GeneratedData.GENERATED_TITLE}" in first_title.text, "Incorrect title displayed"33 34 def should_be_correct_last_title_name(self):35 task_titles = BrowserHelper.find_visible_elements(self.driver, *MainPageLoctors.TASK_TITLES)36 last_added_title = task_titles[-1]37 assert f"{GeneratedData.GENERATED_TITLE}" in last_added_title.text, "Incorrect title displayed"38 39 def should_be_navigation_bar_items(self):40 navigation_items = {41 'import_button': BrowserHelper.find_visible_elements(self.driver, *NavigationBarLocators.IMPORT_BUTTON),42 'gellery_button': BrowserHelper.find_visible_elements(self.driver, *NavigationBarLocators.GALLERY_BUTTON),43 'slideshow_button': BrowserHelper.find_visible_elements(self.driver,44 *NavigationBarLocators.SLIDESHOW_BUTTON),45 'tools_button': BrowserHelper.find_visible_elements(self.driver, *NavigationBarLocators.TOOLS_BUTTON)}46 assert len(navigation_items) == 4, "Not all element of navbar is displayed"47 48 def gallery_should_be_checked(self):49 gallery_button = BrowserHelper.find_visible_element(self.driver, *NavigationBarLocators.GALLERY_BUTTON)50 assert gallery_button.get_attribute("checked") == "true", "The element is not checked"51 52 ...

Full Screen

Full Screen

example_test.py

Source:example_test.py Github

copy

Full Screen

...7 def test_todo_list(self):8 self.open("http://www.angularjs.org")9 todo_selector = '[ng-repeat="todo in todoList.todos"]'10 # Verify that the todos are listed11 todos = self.find_visible_elements(todo_selector)12 self.assert_equal(len(todos), 2)13 self.assert_equal(todos[1].text.strip(), "build an AngularJS app")14 # Verify adding a new todo15 self.type('[ng-model="todoList.todoText"]', "write a protractor test")16 self.click('[value="add"]')17 todos = self.find_visible_elements(todo_selector)18 self.assert_equal(len(todos), 3)...

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