在系统中找到但在詹金斯中找不到的硒元素 [英] Selenium element found in system but not found in Jenkins

查看:133
本文介绍了在系统中找到但在詹金斯中找不到的硒元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的团队最近开始使用Selenium Web Driver和JUnit开发自动化脚本.我面临一个问题,而且我对如何进行工作毫无想法.任何建议都会有用.

My team and I have recently started working on developing automated scripts using Selenium Web Driver and JUnit. I am facing an issue, and I am literally out of ideas on how to proceed. Any suggestions would be useful.

这是问题所在:我有一个页面,在该页面中,我以表格形式上传两个Excel,然后按提交按钮以确认上传.

Here is the problem: I have a page, in which I upload two excels in a form and then press the submit button to confirm the upload.

上载完成后,它将使用数据填充数据库,然后下一页确认每个excel的行数.

When the upload completes it populates the database with the data, and the next page confirms the number of rows for each excel.

我正在尝试获取确认上传的元素,它是标签"类型.

I am trying to get the element that confirms the upload which is a 'label' type.

所有这些都可以在我的PC上本地成功运行(Windows 7,firefox webdriver).

All of this works successfully on locally, on my pc (windows 7, firefox webdriver).

上载代码时,当jenkins生成/执行代码时,我得到一个找不到元素",并且测试失败.

When uploading my code, and when jenkins builds/executes it I get a "Element not found" and the test fails.

由于我看不到jenkins运行的内容,因此我将元素确认(在jenkins上失败)替换为getPageSource().

Since I have no visual access to what jenkins runs, I substituted the element confirmation (which fails on jenkins) with getPageSource().

getPageSource()返回我希望看到的页面,其中包含我要查找的元素(本地和jenkins).

getPageSource() returns the page I expect to see with the element I am trying to find (both locally and on jenkins).

关于可能发生的事情的任何想法吗?

Any ideas as to what may be happening?

注释:

Notes:

有两个10秒的thread.sleep.上传每个excel时一次,单击提交后一次,以确保加载下一页并成功提交excel.

There are two 10sec thread.sleep. One when uploading each excel, and one after clicking submit, to ensure that the next page loads and that the excels are submitted successfully.

我尝试使用xpath定位元素.实际上,我同时使用了Firefox中的Firebug和Chrome中的Web开发人员提供给我的xpath.只是为了确保xpath没有任何问题.这两个xpath都可以在我的本地计算机上成功找到该元素,但是在jenkins上失败.

I try to locate the element using xpath. In fact I used both the xpath given to me by Firebug in Firefox and web developer in Chrome. just to make sure there wasn't any problem with the xpath. Both xpaths locate the element successfully on my local machine but fail on jenkins.

(在本地和Jenkins上)执行测试,我可以看到数据库已按预期填充.

Executing the test (locally and on Jenkins) I can see the database populate as it should.

对不起代码不足,但是我只能分享我的内容.

Excuse the lack of code, but I am restricted as to what I can share.

推荐答案

尝试使用fluentwait而不是Thread.sleep().您的元素可能没有在10秒内加载完毕,您可以尝试

Try using fluentwait instead of Thread.sleep(). Your element might not have been loaded in 10 seconds you may try this

// Waiting 30 seconds for an element to be present on the page, checking
 // for its presence once every 5 seconds.
   Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
   .withTimeout(30, SECONDS)
   .pollingEvery(5, SECONDS)
   .ignoring(NoSuchElementException.class);

WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
 public WebElement apply(WebDriver driver) {
   return driver.findElement(By.id("foo"));
 }
}); 

这里.

这篇关于在系统中找到但在詹金斯中找不到的硒元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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