0

I have used Jenkins using Command prompt earlier. Because of some group policy changes made to the server where I run Jenkins, I started running Jenkins as windows Service (Allow Service to interact with Desktop is checked).

There is a web application on which I am trying to identify the user-id field using the below code and is not able to do so.

When I run the same code in eclipse, it works fine. when I run the same code by stopping Jenkins service and starting using command prompt, it works fine.

But Just not in Jenkins which runs as windows service. Has anyone experienced something like this? what is the solution

WebDriverWait wait = new WebDriverWait(driver,20);

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='user-id']"))

Is this an issue with Jenkins running as service?

Here is the HTML

<div class="l-main">
<div class="container">
<div class="l-content">
<div class="row">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="form-item row">
<label class="col-md-3 col-sm-2 col-xs-12" for="user-id"> User ID </label>
<input id="user-id" class="col-md-6 col-sm-10 col-xs-12" placeholder="User ID" name="UserID" value="" size="23" maxlength="62" type="text"/>
</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
johnsonambrose
  • 115
  • 1
  • 2
  • 15

2 Answers2

0

As per the HTML you have shared instead of a generic xpath as xpath(".//*[@id='user-id']") you can use a more specific xpath as :

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='user-id']"));

You can also use a more granular xpath as :

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@class='col-md-6 col-sm-10 col-xs-12' and @id='user-id']"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Tried using both and it still did not work. As mentioned, the same worked while running the code on Eclipse and through Jenkins from Command prompt. Just not with Jenkins as window service. – johnsonambrose Mar 22 '18 at 16:50
  • This is error message it throws: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //input[@class='col-md-6 col-sm-10 col-xs-12' and @id='user-id'] (tried for 20 second(s) with 500 MILLISECONDS interval) – johnsonambrose Mar 22 '18 at 16:51
  • Another Error : org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //*[@id='user-id'] (tried for 20 second(s) with 500 MILLISECONDS interval) – johnsonambrose Mar 22 '18 at 16:52
0

I have also made unsuccessful attempts to run Jenkins as Windows Service with checked Allow Service to interact with Desktop. This issue is caused by Session 0 isolation.This stackoverflow question is on similar topic and could help you.

K. B.
  • 3,342
  • 3
  • 19
  • 32
  • Thanks. But did you find a solution for this? the links you provided talks about the issue only – johnsonambrose Mar 26 '18 at 14:55
  • Do you have slave machines? My impression from the question is that you have only Jenkins server. https://wiki.jenkins.io/display/JENKINS/Distributed+builds#Distributedbuilds-Differentwaysofstartingagents – K. B. Mar 26 '18 at 17:47