java - I don't want to write driver.findelement(By.xpath("")) again and again -


hi code below: want build function in pass value of xpath, don't have write driver.findelement(by.xpath("")) again , again.

driver.findelement(by.xpath("//*[@id='lead_source']")).sendkeys("existing customer"); driver.findelement(by.xpath("//*[@id='date_closed']")).sendkeys("08/07/2013"); driver.findelement(by.xpath("//*[@id='sales_stage']")).sendkeys("opportuntiy qualification"); driver.findelement(by.xpath("//*[@id='opportunity_monthly_volume']")).sendkeys("10895"); driver.findelement(by.xpath("//*[@id='probability']")).sendkeys("90"); driver.findelement(by.xpath("//*[@id='opportunity_sales_rep']")).sendkeys("sales rep"); driver.findelement(by.xpath("//*[@id='opportunity_sales_regions']")).sendkeys("northeast"); driver.findelement(by.xpath("//*[@id='opportunity_current_lab']")).sendkeys("current lab"); driver.findelement(by.cssselector(payermixcss +"opportunity_medicare")).sendkeys("5"); 

the best way use pageobject pattern. this:

public class myformpageobject {      public myformpageobject enterleadsource(string value) {         driver.findelement(by.id("lead_source")).sendkeys(value);         return this;     }      public myformpageobject enterdateclosed(string value) {         driver.findelement(by.id("date_closed")).sendkeys(value);         return this;     }      //...  }  // in test code myformpo.enterleadsource("existing customer").enter("08/07/2013"); 

note mentionned, should use by.id if have identifier, because xpath slower , not supported implementation of webdriver.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -