从Selenium Webderiver中的IDE/控制台获取用户输入 [英] Get user input from IDE/Console in selenium webderiver

查看:222
本文介绍了从Selenium Webderiver中的IDE/控制台获取用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从用户输入中获取密钥(发送密钥),我应该如何实现呢?

I want to get the key(send key) from user input how should I implement it?

driver.findElement(By.xpath(".//*[@id='vehicleNum']")).sendKeys("1121");

在输入框中,我想要生成什么类型​​的用户,然后再通过硒发送?

in input box what ever user type i want gen then i want to send through selenium?

推荐答案

即使您的问题不清楚,但我假设您需要以下解决方案. 要从文本框中获取输入值,可以使用以下代码:

Even your question is not clear properly but as I am assuming you need below solution. To get the input value from textbox, you can use below code:

 driver.findElement(By.xpath(".//*[@id='vehicleNum']")).sendKeys("1121");
 String str = driver.findElement(By.xpath(".//*[@id='vehicleNum']")).getAttribute("value");
 System.out.println(str);

程序输出将为"1121"

Program output will be "1121"

这篇关于从Selenium Webderiver中的IDE/控制台获取用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆