How to use find_element_by_name method in Airtest

Best Python code snippet using Airtest

contact.py

Source:contact.py Github

copy

Full Screen

...12 def create_contact(self, Contact):13 wd = self.contact.wd14 self.init_contact_creation()15 # first name16 wd.find_element_by_name("firstname").click()17 wd.find_element_by_name("firstname").clear()18 wd.find_element_by_name("firstname").send_keys(Contact.first_name)19 # last name20 wd.find_element_by_name("lastname").click()21 wd.find_element_by_name("lastname").clear()22 wd.find_element_by_name("lastname").send_keys(Contact.last_name)23 # nickname24 wd.find_element_by_name("nickname").click()25 wd.find_element_by_name("nickname").clear()26 wd.find_element_by_name("nickname").send_keys(Contact.nickname)27 # title28 wd.find_element_by_name("title").click()29 wd.find_element_by_name("title").clear()30 wd.find_element_by_name("title").send_keys(Contact.title)31 # company name32 wd.find_element_by_name("company").click()33 wd.find_element_by_name("company").clear()34 wd.find_element_by_name("company").send_keys(Contact.company_name)35 # address36 wd.find_element_by_name("address").click()37 wd.find_element_by_name("address").clear()38 wd.find_element_by_name("address").send_keys(Contact.address)39 # home phone40 wd.find_element_by_name("home").click()41 wd.find_element_by_name("home").clear()42 wd.find_element_by_name("home").send_keys(Contact.home)43 # mobile phone44 wd.find_element_by_name("mobile").click()45 wd.find_element_by_name("mobile").clear()46 wd.find_element_by_name("mobile").send_keys(Contact.mobile)47 # work phone48 wd.find_element_by_name("work").click()49 wd.find_element_by_name("work").clear()50 wd.find_element_by_name("work").send_keys(Contact.work)51 # fax52 wd.find_element_by_name("fax").click()53 wd.find_element_by_name("fax").clear()54 wd.find_element_by_name("fax").send_keys(Contact.fax)55 # first mail56 wd.find_element_by_name("email").click()57 wd.find_element_by_name("email").clear()58 wd.find_element_by_name("email").send_keys(Contact.first)59 # second mail60 wd.find_element_by_name("email2").click()61 wd.find_element_by_name("email2").clear()62 wd.find_element_by_name("email2").send_keys(Contact.second)63 # third mail64 wd.find_element_by_name("email3").click()65 wd.find_element_by_name("email3").clear()66 wd.find_element_by_name("email3").send_keys(Contact.third)67 # homepage68 wd.find_element_by_name("homepage").click()69 wd.find_element_by_name("homepage").clear()70 wd.find_element_by_name("homepage").send_keys(Contact.homepage)71 # birthdate72 if not wd.find_element_by_xpath("//div[@id='content']/form/select[1]//option[7]").is_selected():73 wd.find_element_by_xpath("//div[@id='content']/form/select[1]//option[7]").click()74 if not wd.find_element_by_xpath("//div[@id='content']/form/select[2]//option[2]").is_selected():75 wd.find_element_by_xpath("//div[@id='content']/form/select[2]//option[2]").click()76 wd.find_element_by_name("byear").click()77 wd.find_element_by_name("byear").clear()78 wd.find_element_by_name("byear").send_keys(Contact.birth_year)79 # anniversary80 if not wd.find_element_by_xpath("//div[@id='content']/form/select[3]//option[5]").is_selected():81 wd.find_element_by_xpath("//div[@id='content']/form/select[3]//option[5]").click()82 if not wd.find_element_by_xpath("//div[@id='content']/form/select[4]//option[6]").is_selected():83 wd.find_element_by_xpath("//div[@id='content']/form/select[4]//option[6]").click()84 wd.find_element_by_name("ayear").click()85 wd.find_element_by_name("ayear").clear()86 wd.find_element_by_name("ayear").send_keys(Contact.an_year)87 # second address88 wd.find_element_by_name("address2").click()89 wd.find_element_by_name("address2").clear()90 wd.find_element_by_name("address2").send_keys(Contact.second_address)91 # home address92 wd.find_element_by_name("phone2").click()93 wd.find_element_by_name("phone2").clear()94 wd.find_element_by_name("phone2").send_keys(Contact.home_address)95 # notes96 wd.find_element_by_name("notes").click()97 wd.find_element_by_name("notes").clear()98 wd.find_element_by_name("notes").send_keys(Contact.notes)99 self.submit_contact_creation()100 self.contact_cache = None101 def select_first_contact(self):102 wd = self.contact.wd103 wd.find_element_by_name("selected[]").click()104 def select_contact_by_index(self, index):105 wd = self.contact.wd106 wd.find_elements_by_name("selected[]")[index].click()107 def delete_contact_by_index(self, index):108 wd = self.contact.wd109 self.select_contact_by_index(index)110 wd.find_element_by_xpath(".//*[@id='content']/form[2]/div[2]/input").click()111 wd.switch_to_alert().accept()112 self.contact_cache = None113 def modify_first_contact(self, index):114 self.modify_contact_by_index(0)115 def modify_contact_by_index(self, index, Contact=None):116 wd = self.contact.wd117 # init contact modification118 self.select_contact_by_index(index)119 wd.find_element_by_name("selected[]").click()120 wd.find_element_by_xpath(".//*[@id='maintable']/tbody/tr[2]/td[8]/a/img").click()121 # first name122 wd.find_element_by_name("firstname").click()123 wd.find_element_by_name("firstname").clear()124 wd.find_element_by_name("firstname").send_keys(Contact.first_name)125 # last name126 wd.find_element_by_name("lastname").click()127 wd.find_element_by_name("lastname").clear()128 wd.find_element_by_name("lastname").send_keys(Contact.last_name)129 # nickname130 wd.find_element_by_name("nickname").click()131 wd.find_element_by_name("nickname").clear()132 wd.find_element_by_name("nickname").send_keys(Contact.nickname)133 # title134 wd.find_element_by_name("title").click()135 wd.find_element_by_name("title").clear()136 wd.find_element_by_name("title").send_keys(Contact.title)137 # company name138 wd.find_element_by_name("company").click()139 wd.find_element_by_name("company").clear()140 wd.find_element_by_name("company").send_keys(Contact.company_name)141 # address142 wd.find_element_by_name("address").click()143 wd.find_element_by_name("address").clear()144 wd.find_element_by_name("address").send_keys(Contact.address)145 # home phone146 wd.find_element_by_name("home").click()147 wd.find_element_by_name("home").clear()148 wd.find_element_by_name("home").send_keys(Contact.home)149 # mobile phone150 wd.find_element_by_name("mobile").click()151 wd.find_element_by_name("mobile").clear()152 wd.find_element_by_name("mobile").send_keys(Contact.mobile)153 # work phone154 wd.find_element_by_name("work").click()155 wd.find_element_by_name("work").clear()156 wd.find_element_by_name("work").send_keys(Contact.work)157 # fax158 wd.find_element_by_name("fax").click()159 wd.find_element_by_name("fax").clear()160 wd.find_element_by_name("fax").send_keys(Contact.fax)161 # first mail162 wd.find_element_by_name("email").click()163 wd.find_element_by_name("email").clear()164 wd.find_element_by_name("email").send_keys(Contact.first)165 # second mail166 wd.find_element_by_name("email2").click()167 wd.find_element_by_name("email2").clear()168 wd.find_element_by_name("email2").send_keys(Contact.second)169 # third mail170 wd.find_element_by_name("email3").click()171 wd.find_element_by_name("email3").clear()172 wd.find_element_by_name("email3").send_keys(Contact.third)173 # homepage174 wd.find_element_by_name("homepage").click()175 wd.find_element_by_name("homepage").clear()176 wd.find_element_by_name("homepage").send_keys(Contact.homepage)177 # birthdate178 if not wd.find_element_by_xpath("//div[@id='content']/form/select[1]//option[7]").is_selected():179 wd.find_element_by_xpath("//div[@id='content']/form/select[1]//option[4]").click()180 if not wd.find_element_by_xpath("//div[@id='content']/form/select[2]//option[3]").is_selected():181 wd.find_element_by_xpath("//div[@id='content']/form/select[2]//option[6]").click()182 wd.find_element_by_name("byear").click()183 wd.find_element_by_name("byear").clear()184 wd.find_element_by_name("byear").send_keys(Contact.birth_year)185 # anniversary186 if not wd.find_element_by_xpath("//div[@id='content']/form/select[3]//option[5]").is_selected():187 wd.find_element_by_xpath("//div[@id='content']/form/select[3]//option[5]").click()188 if not wd.find_element_by_xpath("//div[@id='content']/form/select[4]//option[6]").is_selected():189 wd.find_element_by_xpath("//div[@id='content']/form/select[4]//option[6]").click()190 wd.find_element_by_name("ayear").click()191 wd.find_element_by_name("ayear").clear()192 wd.find_element_by_name("ayear").send_keys(Contact.an_year)193 # second address194 wd.find_element_by_name("address2").click()195 wd.find_element_by_name("address2").clear()196 wd.find_element_by_name("address2").send_keys(Contact.second_address)197 # home address198 wd.find_element_by_name("phone2").click()199 wd.find_element_by_name("phone2").clear()200 wd.find_element_by_name("phone2").send_keys(Contact.home_address)201 # notes202 wd.find_element_by_name("notes").click()203 wd.find_element_by_name("notes").clear()204 wd.find_element_by_name("notes").send_keys(Contact.notes)205 # submit contact modification206 wd.find_element_by_name("update").click()207 self.contact_cache = None208 def count(self):209 wd = self.contact.wd210 self.contact.open_home_page()211 return len(wd.find_elements_by_name("selected[]"))212 contact_cache = None213 def get_contact_list(self):214 if self.contact_cache is None:215 wd = self.contact.wd216 self.contact.open_home_page()217 self.contact_cache = []218 for element in wd.find_elements_by_xpath("//tr[@name='entry']"):219 first_name = element.find_element_by_xpath("./td[3]").text220 last_name = element.find_element_by_xpath("./td[2]").text221 id = element.find_element_by_name("selected[]").get_attribute("value")222 self.contact_cache.append(Contact(first_name=first_name, last_name=last_name, id=id))...

Full Screen

Full Screen

calculatortest.py

Source:calculatortest.py Github

copy

Full Screen

...33 displaytext = displaytext.rstrip(' ')34 displaytext = displaytext.lstrip(' ')35 return displaytext36 def test_initialize(self):37 self.driver.find_element_by_name("Clear").click()38 self.driver.find_element_by_name("Seven").click()39 self.assertEqual(self.getresults(),"7")40 self.driver.find_element_by_name("Clear").click()41 def test_addition(self):42 self.driver.find_element_by_name("One").click()43 self.driver.find_element_by_name("Plus").click()44 self.driver.find_element_by_name("Seven").click()45 self.driver.find_element_by_name("Equals").click()46 self.assertEqual(self.getresults(),"8")47 def test_combination(self):48 self.driver.find_element_by_name("Seven").click()49 self.driver.find_element_by_name("Multiply by").click()50 self.driver.find_element_by_name("Nine").click()51 self.driver.find_element_by_name("Plus").click()52 self.driver.find_element_by_name("One").click()53 self.driver.find_element_by_name("Equals").click()54 self.driver.find_element_by_name("Divide by").click()55 self.driver.find_element_by_name("Eight").click()56 self.driver.find_element_by_name("Equals").click()57 self.assertEqual(self.getresults(),"8")58 def test_division(self):59 self.driver.find_element_by_name("Eight").click()60 self.driver.find_element_by_name("Eight").click()61 self.driver.find_element_by_name("Divide by").click()62 self.driver.find_element_by_name("One").click()63 self.driver.find_element_by_name("One").click()64 self.driver.find_element_by_name("Equals").click()65 self.assertEqual(self.getresults(),"8")66 def test_multiplication(self):67 self.driver.find_element_by_name("Nine").click()68 self.driver.find_element_by_name("Multiply by").click()69 self.driver.find_element_by_name("Nine").click()70 self.driver.find_element_by_name("Equals").click()71 self.assertEqual(self.getresults(),"81") 72 def test_subtraction(self):73 self.driver.find_element_by_name("Nine").click()74 self.driver.find_element_by_name("Minus").click()75 self.driver.find_element_by_name("One").click()76 self.driver.find_element_by_name("Equals").click()77 self.assertEqual(self.getresults(),"8")78if __name__ == '__main__':79 suite = unittest.TestLoader().loadTestsFromTestCase(SimpleCalculatorTests)...

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