-4

While working on code written in Java to automate clicking of a search button on a certain website, i have come across an interesting problem.

The java code runs in loops and locates plus clicks the search button on every iteration. This works well for initial two-three iterations but then the code breaks. If i click on this web-element (a button) manually during execution before the breaking of code, everything works well.

Command in Java:

WebElement shineWebElementSearchButton = shineWaitLocal.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[id=id_searchButton]")));
shineWebElementSearchButton.click();
WebElement shineWebElementSearchBoxPopUpField1 = shineWaitLocal.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[id=id_q]")));
shineWebElementSearchBoxPopUpField1.sendKeys("Testing Automation Selenium Qa");

The error:

Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.cssSelector: input[id=id_q] (tried for 30 second(s) with 500 MILLISECONDS interval)
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'ADMIN-PC', ip: '192.168.2.8', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\admin\AppData\Local\Temp\rust_mozprofile.tYzdI4bJaghM, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, moz:headless=false, platform=XP, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=57.0, platformVersion=10.0, moz:processID=8664, browserName=firefox, javascriptEnabled=true, platformName=XP, moz:webdriverClick=false}]
Session ID: 89991b7d-9acd-485c-bc59-b537ece2af76
    at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:82)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231)
    at autoApplyShine.applyForJobs.applyForJobsFunctionality(applyForJobs.java:32)
    at autoApplyShine.ApplyShine.main(ApplyShine.java:28)
James Z
  • 11,838
  • 10
  • 25
  • 41
sudeept
  • 11
  • 1
  • 6
  • 1
    People have formatted your question several times, and then you come and mess it up again. Before making more changes or posting new questions, please take your time to look into how to format things properly (e.g. code sample button / indenting with 4 spaces). – James Z Feb 18 '18 at 06:10
  • 1
    Also next time please write a proper title. Things like "unique scenario" or "pls take a look" (or anything similar with different words) do not belong into a title. – James Z Feb 18 '18 at 06:11

1 Answers1

2

You have to take care of a couple of points here as follows :

  • Once you perform shineWaitLocal for the WebElement shineWebElementSearchButton next you are invoking click() method. Hence instead of ExpectedConditions clause of visibilityOfElementLocated you must be using elementToBeClickable as follows :

    shineWaitLocal.until(ExpectedConditions.elementToBeClickable(Locator Strategy)).click();
    

But, your code is generating TimeoutException even when waiting for visibility of element which implies that the Locator Strategy which you have adapted doesn't identifies the WebElement uniquely. So we have to take help of a locator which uniquely identifies the element.

Now there is a clear mismatch between the Locators you have used in your code ( which is "button[id=id_searchButton]") and in the error stack trace (which is input[id=id_q])

  • As per the locator in your code it must be :

    By.cssSelector("button#id_searchButton")
    
  • As per the error trace log the locator must be :

    By.cssSelector("input#id_q")
    

Note : It is quite clear from the trace logs you are using Selenium Client v3.6.0 but surprisingly the GeckoDriver version is missing from the below trace log which could have made the debugging much more easier and possible holds the key to answer your question :

Driver info: org.openqa.selenium.firefox.FirefoxDriver
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • Hi Debanjan, I have made the changes to the code as you have proposed.Please take a look at the edited post. (This also solves the locator confusion). Still the code is breaking – sudeept Feb 18 '18 at 05:20
  • @sudeept Update the question with the relevant HTML. – DebanjanB Feb 18 '18 at 06:11
  • Please find the relevant HTML here: _________ – sudeept Feb 20 '18 at 20:03
  • Even after changing the version from3.6 to 3.9 the same error appears, not every time but at sometimes : Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.cssSelector: button[id=id_searchButton] (tried for 30 second(s) with 500 MILLISECONDS interval) Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:22.379Z' – sudeept Feb 21 '18 at 15:06