无法使用硒传递客户 ID 中的任何值

Not able to pass any value in the customer id using selenium

我正在尝试下面的页面

https://netbanking.hdfcbank.com/netbanking/

我无法使用 selenium 网络驱动程序向客户 ID 发送任何值。在这方面需要帮助。

我的代码:

public class login { 
   static WebDriver driver; 
   public static void main(String[] args) { 
      driver= new FirefoxDriver(); 
      driver.get("netbanking.hdfcbank.com/netbanking/"); 
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
      driver.findElement(By.xpath("html/body/form/table[2]/tbody‌
                                   ​/tr/td[2]/table/tbod‌​y/tr[1]
                                   /td[1]/table/‌​tbody/tr[3]/td[2]
                                   /ta‌​ble/tbody/tr[2]/td[2‌​]/span/input"))
      .send‌​Keys("1234"); 
} 
}

首先,您使用的URL不会被selenium浏览器轻易识别。将 URL 更改为 "https://netbanking.hdfcbank.com/netbanking/"

其次,主页面由2个Frames组成,即login_pagefooter。您对 login_page 框架感兴趣,因此您需要将 selenium 的焦点切换到该框架。

要将焦点切换到框架,请在 driver.findElement() 之前添加此行:

driver.switchTo().frame("login_page"); //frame() requires either the name or id of frame or it's index

第三,使用 xpath "//input[@name='fldLoginUserId']",而不是您当前拥有的 xpath。简短易懂

工作解决方案:

driver.get("https://netbanking.hdfcbank.com/netbanking/");             
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
driver.switchTo().frame("login_page");
driver.findElement(By.xpath("//input[@name='fldLoginUserId']")).sendKeys("1234");