简体   繁体   English

如何在浏览器中获取表单值以使用webdriver

[英]How to get form values in browser to watir webdriver

I have installed my application and it is running on following URL 我已经安装了我的应用程序,它正在以下URL上运行

http://localhost:3000 HTTP://本地主机:3000

Above URL will the load form with some fields, Then I will the fill the data in the required field and then submit form. 上面的URL将是带有一些字段的加载表单,然后我将填写必填字段中的数据,然后提交表单。 My div element will displayed at the bottom of the page. 我的div元素将显示在页面底部。 Picture will be displayed inside the iframe with in the div element. 图片将显示在div元素内的iframe内。

User will the above URL and then submit form. 用户将上面的URL然后提交表单。 After submitting the form, Picture should be downloaded into their local machine. 提交表单后,应将图片下载到本地计算机中。

Right I am calling the following line after form submission, how can I get the existing page into the browser object and download screenshot? 正确我在表单提交后调用以下行,如何将现有页面放入浏览器对象并下载屏幕截图?

browser = Watir::Browser.new
b.div(:id => "phone_shell").screenshot("/home/user/Documents/preview.png")

I found few problems in your code 我在你的代码中发现了一些问题

screenshot method is not available for element object, it's available for browser object and also you need to call the method save to save the file in the destination folder. screenshot方法不适用于元素对象,它可用于浏览器对象,您还需要调用方法save以将文件保存在目标文件夹中。 So write the following code, it would work. 所以写下面的代码,它会工作。

Code to get the html of the page 用于获取页面html的代码

b.html

Code to take the screenshot 代码截取屏幕截图

b.screenshot.save("/home/user/Documents/preview.png")

Now this will save the image in the destination folder. 现在,这将保存目标文件夹中的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM