我正在尝试下面的页面
https://netbanking.hdfcbank.com/netbanking/
我无法使用selenium web驱动程序向客户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/tbody/tr[1]
/td[1]/table/tbody/tr[3]/td[2]
/table/tbody/tr[2]/td[2]/span/input"))
.sendKeys("1234");
}
}
答案 0 :(得分:1)
首先,您使用的网址不会被selenium浏览器轻松识别。将网址更改为"https://netbanking.hdfcbank.com/netbanking/"
其次,主页面由2 Frames
即login_page
和footer
组成。您对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");