java selenium null pointer -
i not sure how solve null pointer exception. thought page properties not found page gets loaded causing this. if 1 kindly point out helpful. in advance.
code:
import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.chrome.chromedriver; public class flight { public static webdriver driver; //this following section browser , getting url public static webdriver browser(){ system.setproperty("webdriver.chrome.driver", "c:\\users\\chq-sheikhr\\downloads\\eclipse\\chromedriver.exe"); webdriver driver= new chromedriver(); driver.get("https://www.orbitz.com/flights"); return driver; } //this following section getting properties of page public static void getpageproperties(string ff,string ft, string fd, string rd){ //flight f= new flight(); -- thought getting null pointer because properties not found //f.browser(); -- putting them here how these webelements found , null pointer issue solved no webelement flyfrom= driver.findelement(by.id("flight-origin")); webelement flyto= driver.findelement(by.id("flight-destination")); webelement flydate= driver.findelement(by.id("flight-departing")); webelement returndate= driver.findelement(by.id("flight-returnin")); webelement flight_search_btn= driver.findelement(by.id("search-button")); flyfrom.sendkeys(ff); flyto.sendkeys(ft); flydate.sendkeys(fd); returndate.sendkeys(rd); flight_search_btn.click(); } // following section have arguments provide flight search public static void main (string [] args){ flight f= new flight(); f.browser(); f.getpageproperties("msp", "sea", "05/01/2017", "05/05/2017"); } }
error:
only local connections allowed. exception in thread "main" java.lang.nullpointerexception @ flight.getpageproperties(flight.java:27) @ flight.main(flight.java:47)
you have change
webdriver driver= new chromedriver();
to
driver= new chromedriver();
Comments
Post a Comment