eclipse - Selenium webdriver with JAVA -
**when run code. getting error exception in thread "main" java.lang.nullpointerexception
.can tell me how fix it?
package insights; import java.util.concurrent.timeunit; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.chrome.chromedriver; public class test_getinsights { static webdriver driver; public static void main(string[] args) throws exception { system.setproperty("webdriver.chrome.driver", "c://selenium-2.53.0/chromedriver.exe"); webdriver driver = new chromedriver(); driver.get("https://getinsights.co"); driver.manage().window().maximize(); //login// driver.findelement(by.xpath("html/body/div[1]/div/nav/div/div[2]/ul/li[7]/a")).click(); //login_page// driver.findelement(by.xpath(".//*[@id='form']/div[1]/input")).sendkeys("testgetinsight@gmail.com"); driver.findelement(by.xpath("html/body/div[1]/div/div[2]/div/form/div[2]/input")).sendkeys("airloyal"); driver.findelement(by.xpath("html/body/div[1]/div/div[2]/div/form/div[3]/div[2]/button")).click(); //create_survey// thread.sleep(10000); driver.findelement(by.xpath(".//*[@id='rootid']/div[2]/div[1]/div[4]/div[2]/div/div/button")).click(); //create_question// driver.manage().timeouts().implicitlywait(700, timeunit.seconds); driver.findelement(by.xpath("html/body/div[1]/div/div/div[2]/div[1]/div/button[2]")).click(); driver.findelement(by.xpath(".//*[@id='rootid']/div/div/div[2]/div[2]/div[1]/div[3]/div/div/div/button[2]")).click(); system.out.println("driver=" + driver); ****driver.findelement(by.xpath(".//*[@id='question 14998']/div/textarea")).sendkeys("which best website learn java?");**** // null pointer exception// driver.findelement(by.xpath(".//*[@id='rootid']/div/div/div[2]/div[2]/div[1]/div[5]/button")).click(); //post_question driver.findelement(by.cssselector(".clear.opentextstyle.ng-pristine.ng-untouched.ng-invalid.ng-invalid-required")).sendkeys("java"); driver.findelement(by.cssselector(".launch-btn.ng-binding")).click(); driver.quit(); driver.close(); } }
i dont think there element statement. please add check null before invoking sendkeys
webelement element = driver.findelement(by.xpath(".//*[@id='question 14998']/div/textarea")); if ( element != null ){ element.sendkeys("which best website learn java?") }else //do thing }
Comments
Post a Comment