Java Selenium web驱动程序填充字段保存输出
我是硒的新手,所以很抱歉这个问题。但我在谷歌上找不到。 因此,我有一个简单的Java代码:Java Selenium web驱动程序填充字段保存输出,java,selenium,xpath,Java,Selenium,Xpath,我是硒的新手,所以很抱歉这个问题。但我在谷歌上找不到。 因此,我有一个简单的Java代码: public static void main(String[] args) throws Exception { // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); // Go to the Google Suggest home page driver.
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// Go to the Google Suggest home page
driver.get("http://tudakozo.telekom.hu/main?xml=main&xsl=main");
// Enter the query string "Cheese"
WebElement query = driver.findElement(By.xpath("id('searchByName')/x:input[2]"));
网页顺便说一句:[链接][1]
我想把左边的盒子装满。为此,我需要一些selenium命令:s.fill(这里是xpath,“用文本填充”)
对于xpath,我使用firefox插件并查找xpath:
我无法发布图像,因此这里有一个链接:
然后,我会在当地的未来得到一些Capthca断路器,但如果你有建议,我会接受:)
无论如何,我需要下载图片并手动填充。然后单击
“keresés”按钮xp誓言:id('searchByName')/x:input[2]
但是在第一步中我失败了,我无法检查seleinum(JAVA)是否填充了字段
**那么主要的问题是我如何填写字段,下载图片
通过selenium(JAVA)中的xpath,然后保存输出**
example : *név*(name) :first field : **Szabó István** and
*Település*(city)/the field where there is a little pink text/ : **Gyula**
您可以使用Selenium和Java保存这样的图像
string url = "yourimage.png";
BufferedImage bufImgOne = ImageIO.read(url);
ImageIO.write(bufImgOne, "png", new File("test.png"));
至于填写表格
driver.findElement(By.id("yourID")).sendKeys("text you need to send");
如果您希望从xpath获取图像src以下载该src,请执行此操作
WebElement img = driver.findElement(By.id("foo")); // or xpath whichever you prefer
String src = img.getAttribute("src");
你必须在测试中跳过验证码。要求开发人员准备一个参数,该参数将在URL中传递给应用程序,这将允许您使用应用程序而无需填写验证码 我的测试就是这样做的
当然,除非您正在测试验证码功能:)但是我没有链接,只有xpath,一些id ed->跟随兄弟姐妹->idk elemetn->链接在这里。我可以通过link/xpath下载吗?同样的问题是,我可以使用什么样的xpath by.xpath(“//xpath?”)我刚刚编辑了我的答案,基本上是使用xpath还是按id、类等。。。为了获得src属性,您可以使用该属性下载image.hi。我尝试下载一个类似于您所说的文件:WebElement img=driver.findelelement(By.xpath(“//form[@id='searchByName']]/table/tbody/tr/td/img”);//或者xpath,以您喜欢的字符串src=img.getAttribute(“src”)为准;系统输出打印LN(src);URI=新URI(src);URL=uri.toURL();buffereImage bufImgOne=ImageIO.read(url);write(bufImgOne,“jph”,新文件(“test.png”);它获取链接:但它给了我错误:javax.imageio.IIOException:无法从。。。