这篇文章主要围绕Java和Selenium用于Web表单填充吗?和selenium填写表单展开,旨在为您提供一份详细的参考资料。我们将全面介绍Java和Selenium用于Web表单填充吗?的优缺点,
这篇文章主要围绕Java和Selenium用于Web表单填充吗?和selenium填写表单展开,旨在为您提供一份详细的参考资料。我们将全面介绍Java和Selenium用于Web表单填充吗?的优缺点,解答selenium填写表单的相关问题,同时也会为您带来Docker,Django和Selenium-Selenium无法连接、java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0、java – Selenium WebDriver中selenium.waitForPageToLoad(“30000”)的等效代码是什么?、java – 用于检查Selenium WebDriver中项目列表的循环的实用方法。
本文目录一览:- Java和Selenium用于Web表单填充吗?(selenium填写表单)
- Docker,Django和Selenium-Selenium无法连接
- java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0
- java – Selenium WebDriver中selenium.waitForPageToLoad(“30000”)的等效代码是什么?
- java – 用于检查Selenium WebDriver中项目列表的循环
Java和Selenium用于Web表单填充吗?(selenium填写表单)
我想自动填写网络表格。我使用Selenium IDE创建了一个脚本,该脚本以搜索网页中指定文本的命令结尾。
我想根据此TEXT采取措施。如果text =恭喜,请发送电子邮件至某个地址。如果不是,则单击“确定”按钮。我不认为Selenium IDE可以执行此If-
else逻辑并自己发送邮件(在硒中使用if /
else)。
因此,我想到了使用Java代码来“运行”这个Selenium HTML脚本,找出是否找到了所需的文本-
如果是,则发送邮件。否则,Java代码将“单击”确定按钮。
这种方法有意义吗?可以使用Java和某种Selenium Java API来做到这一点吗?
答案1
小编典典您无法在Selenium IDE中可靠地执行此操作。真正的方法是使用Java + Selenium WebDriver,事情变得很简单:
// acquire textif (acquire.equals("congratulations")) { sendMail("Something, tada badum tss!");} else { driver.findElement(By.id("myButton")).click();}
邮件发送部分可以通过数千种方式来完成,具体取决于您要执行的方式。开始的基本点是JavaMail网页。如果您不满意,也可以查看最常用的包装器:Apache
Commons Email和Jodd。
Docker,Django和Selenium-Selenium无法连接
我已经将Docker配置为使用docker-compose.yml运行Postgres和Django,并且工作正常。
我遇到的麻烦是Selenium无法连接到Django liveserver。
现在(至少对我而言),django必须访问selenium才能控制浏览器,而selenium必须访问django才能访问服务器。
我已经尝试从此处使用docker-
compose.yml的以下配置使用docker’大使’模式:https
:
//github.com/docker/compose/issues/666
postgis:
dockerfile: ./docker/postgis/Dockerfile
build: .
container_name: postgis
django-ambassador:
container_name: django-ambassador
image: cpuguy83/docker-grand-ambassador
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
command: "-name django -name selenium"
django:
dockerfile: ./docker/Dockerfile-dev
build: .
command: python /app/project/manage.py test my-app
container_name: django
volumes:
- .:/app
ports:
- "8000:8000"
- "8081:8081"
links:
- postgis
- "django-ambassador:selenium"
environment:
- SELENIUM_HOST=http://selenium:4444/wd/hub
selenium:
container_name: selenium
image: selenium/standalone-firefox-debug
ports:
- "4444:4444"
- "5900:5900"
links:
- "django-ambassador:django"
当我检查http:// DOCKER-MACHINE-IP:4444 / wd / hub / static / resource /
hub.html时,
我可以看到Firefox启动了,但是由于Firefox无法连接到Django,所有测试都失败了
'Firefox can't establish a connection to the server at localhost:8081'
我也在这里https://github.com/docker/compose/issues/1991尝试了此解决方案,
但是这不起作用,因为我无法让django同时连接到Postgis和Selenium
'django.db.utils.OperationalError: could not translate host name "postgis" to address: Name or service not known'
我尝试使用下面列出的网络功能
postgis:
dockerfile: ./docker/postgis/Dockerfile
build: .
container_name: postgis
net: appnet
django:
dockerfile: ./docker/Dockerfile-dev
build: .
command: python /app/project/manage.py test foo
container_name: django
volumes:
- .:/app
ports:
- "8000:8000"
- "8081:8081"
net: appnet
environment:
- SELENIUM_HOST=http://selenium:4444/wd/hub
selenium:
container_name: selenium
image: selenium/standalone-firefox-debug
ports:
- "4444:4444"
- "5900:5900"
net: appnet
但结果是一样的
'Firefox can't establish a connection to the server at localhost:8081'
那么我怎样才能使selenium连接到Django?
我已经玩了好几天了-非常感谢您的帮助。
更多信息
另一个怪异的事情是,如果我运行./manage.py test foo,那么当测试服务器运行时 不 使用docker
(使用我的virtualenv等旧配置)时,我可以通过http://
localhost:8081上的任何浏览器访问服务器,并且获取提供的网页,但是如果我在docker下运行等效命令,则无法访问测试服务器。这很奇怪,因为我正在映射端口8081:8081-这与之相关吗?
注意:我正在使用OSX和Docker v1.9.1
java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0
public class sikuli { public static void main(String[] args) throws Exception { //Screen screen=new Screen(); //screen.click("//home//exeter//Pictures//googlechrome.png"); System.setProperty("webdriver.chrome.driver","//home//exeter//Documents//chromedriver"); WebDriver driver=new ChromeDriver(); driver.get("https://mail.google.com");
Starting ChromeDriver 2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3) on port 11320
Only local connections are allowed.
Oct 19,2016 10:07:22 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session,assuming Postel’s Law holds true on the remote end
Oct 19,2016 10:08:22 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread “main” org.openqa.selenium.NoSuchSessionException: no such session
(Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.4.0-43-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
Build info: version: ‘unkNown’,revision: ‘350cf60’,time: ‘2016-10-13 10:43:56 -0700’
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unkNown error: Chrome Failed to start: exited abnormally
解决方法
java – Selenium WebDriver中selenium.waitForPageToLoad(“30000”)的等效代码是什么?
selenium.waitForPagetoLoad("30000");
Selenium WebDriver中的等效java代码是什么?
解决方法
>如果你需要等待60秒,你可以使用Thread.sleep(60000)
>如果您想确保页面已加载(可能小于或大于60秒),我建议使用以下方法:
确定目标网页中的元素&等待它可以点击.然后您确定该页面已加载.
webdriverwait wait = new webdriverwait(driver,120); wait.until(ExpectedConditions.elementToBeClickable(By.id(id)));
WebDriver等待最多120秒.对于可点击的元素.如果元素在此之前可单击,则测试将进行.
java – 用于检查Selenium WebDriver中项目列表的循环
List <WebElement> listofItems = wd.findElements(By.xpath("//*[starts-with(@id,'result_')]//div//div[1]//div//a//img")); for (int i=1; i<=listofItems.size(); i++) { listofItems.get(i).click(); wd.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); System.out.println(i); System.out.println("pass"); wd.navigate().back(); }
解决方法
List <WebElement> listofItems = wd.findElements(By.xpath("//*[starts-with(@id,'result_')]//div//div[1]//div//a//img")); webdriverwait wait = new webdriverwait(wd,20); //Wait time of 20 seconds for (int i=1; i<=listofItems.size(); i++) { /*Getting the list of items again so that when the page is navigated back to,then the list of items will be refreshed again */ listofItems = wd.findElements(By.xpath("//*[starts-with(@id,'result_')]//div//div[1]//div//a//img")); //Waiting for the element to be visible //Used (i-1) because the list's item start with 0th index,like in an array wait.until(ExpectedConditions.visibilityOf(listofItems.get(i-1))); //Clicking on the first element listofItems.get(i-1).click(); wd.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); System.out.print(i + " element clicked\t--"); System.out.println("pass"); wd.navigate().back(); }
所以,上面我稍微调整了一下你的代码并获得相关的评论,其中包含了更改以及原因.希望这对你有用.
总结
以上是小编为你收集整理的java – 用于检查Selenium WebDriver中项目列表的循环全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
关于Java和Selenium用于Web表单填充吗?和selenium填写表单的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Docker,Django和Selenium-Selenium无法连接、java – chrome无法在Selenium Webdriver中运行.我使用的是selenium 3.0.1 chrome v-54.0、java – Selenium WebDriver中selenium.waitForPageToLoad(“30000”)的等效代码是什么?、java – 用于检查Selenium WebDriver中项目列表的循环等相关知识的信息别忘了在本站进行查找喔。
本文标签: