2013-10-25 74 views
0

当我试图通过TestNG打开一个站点时,安全页面即将到来,为此我点击了一个链接文本“继续访问本网站(不推荐)”。我通过TestNG编码完成的,但它给java.lang.NullPointerException错误。关于链接文本无法正常工作的Click()函数

,这是我努力的代码......

public class Registration { 
    WebDriver driver; 
    WebElement element; 
    WebElement element2; 
    WebDriverWait waiter; 
    @Test(priority = 1) 
    public void register_With_Cash() throws RowsExceededException, BiffException, WriteException, IOException 
     { 
     File file = new File("D:\\IEDriverServer.exe"); 
     System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); 

     driver=new InternetExplorerDriver(); 
     driver.get("https://172.25.155.250/loginpage.aspx");   
     sleep(10000); 

     waiter.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Continue to this website (not recommended)."))); 
     driver.findElement(By.linkText("Continue to this website (not recommended).")).click(); 
     sleep(50000); 

感谢名单提前为任何形式的帮助。

+0

哪条线给你例外? –

+0

this one .............. waiter.until(ExpectedConditions.presenceOfElementLocated(By.linkText(“Continue to this website(not recommended)。”))); – imtiyaz

+0

请将您的例外和确切的行粘贴到您的源代码中 – Apostolos

回答

0

您可以使用下面的javascript来点击Continue to the Website(not recommended)链接。

driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()"); 
+0

但它给出警告“方法GoToUrl(字符串)是未定义的类型WebDriver.Navigation” – imtiyaz

+0

我已修改为“driver.navigate()。”(“javascript:document.getElementById('overridelink')。click () “);” .....现在它正在工作.... thanx很多 – imtiyaz