New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selenium Click functionality does not work consistently #4075
Comments
This is a case of waiting for the relevant cues to know when to carry on. We have the WebDriver Wait classes that simplify this for you. |
Waits are already present. Wait passes and click does not work randomly with no exception. Page is not changing during this process. If this was the case if Wait class then I'd have got some exception. In this case I am not getting any exception. I request to reopen the bug. I have seen many people across the world are facing this issue are left with no solution. |
We will gladly reopen this when you have a test case that shows this issue consistently. Unfortunately until then there is nothing that we can do. Events not added to a DOM element by the time you click wouldnt throw an error, especially since the web is asynchronous, and the test would try carry on but then not hit the relevant issue. |
Hi @AutomatedTester |
It is a known issue that IE clicks can sometimes be flaky. Here is ruby code (You'll need to adapt, that possible could help)
This will then re-click everytime the next page isn't open, until it is. Not brilliant code, but it gets the job done. As for FF / Chrome, you're on your own there |
Thanks for the suggestion @luke-hill . That was just one of the case. Sometime user moves to different page after click on some element sometime user will remain on same page. Beside, I have some validation added after many click which fails when click does not work. This failure is not due to application error but click did not work so next page did not load. This is kind of false failure. |
Exactly the same situation here. I'm running a Firefox on windows 10. It sometimes work and sometimes doesn't, which is driving me crazy. |
A workaround: Thread.sleep() for some time before the click, and even before starting to look for the element. This is for the situation where you want to click on something right after refreshing/redirecting the page. Looks like the click might be thrown away, if you try to click while the page is still loading. In my case, it needs to sleep for 6000 ms. Not a good solution, but can get things moving, hope it helps. |
@0019 , putting hard coded sleep is not a good solution. I tried 3 seconds of sleep and it did not solve the problem. However, it reduced failures a bit. But, if the DOM status is "completed", then why do we even need hard coded sleep? Is something browser does after DOM is ready? i.e. binding events with Objects? If yes, can we know the status of such thing is completed or not? |
@vinaybond , I've upgraded my method to abandon the sleeping. I'm now using the driver as JavascriptExecutor to execute js command to click it. It works fine for me. To make it 100% hit, you may need to use ExpectedConditions to wait for the element to be visible first. |
Hi @0019, Here is how I am using JS to click on element. It is written in python:
I also tried adding hard coded sleep of 2s before clicking. Any suggestion is welcome. |
I had a problem similar to vinaybond one and I realise that the reason for the click operation not working was that the element was not completely visible in the windows. |
Here is the workaround:
In above example, my action is "element present" (Button1). It can be sometime else. In that case, you have to write a different login. This has worked well for me |
In Chrome I changed from a zoom of 90% to 100% and that solved the problem. |
@Edzarius you gotta be kidding me!. BTW, how did you find the issue that zoom is the problem. Why is it so. |
@mamohanc this is a long standing issue with chromedriver https://bugs.chromium.org/p/chromedriver/issues/detail?id=628 |
facing similar issue . Tests fails intermittently due to this. Logs show click operation is passed but button is not clicked, I even tried wait and EC.element_to_be_clickable before performing click , still am facing this inconsistent failure for button click. can someone please share some workaround for this ? |
Hi one work around which can be done in this is every time when you want to click any element. |
Hi ,
|
Ideally writing any logic inside a catch block is not recommended . You should use finally block to get your work done. |
@abutremutante have you found a solution? having the same problem :( |
This will solve the problem. int timeout=0; try { }catch(Exception e){
} |
Good day, I have encountered the same issue while automating some tests for documents downloading Note:
|
Can you share the code you are using also after clicking on downloading
button how are you making sure that the script is not terminated before the
complete downloading has been done.
Thanks,
…On Thu, May 10, 2018 at 6:28 PM, slapadus ***@***.***> wrote:
Good day,
I have encountered the same issue while automating some tests for
documents downloading
with Selenium 3.5.3 and Chrome 65.
I have noticed that WebElement click() method randomly terminate without
exception but no click is performed (so my files are never downloaded...)
My solution was to implement a retry mechanism (loop until job is done or
number of retries is reached)
Any help ?
Thanks
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4075 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AUJQTDcm12b7AAyVMVKJmE0WMLg_515Hks5txDmJgaJpZM4Nl_NU>
.
|
// 1 - the code (extract) // 2 - the class FileDownloadUtility (extract with download method)
} /* FileDownloadUtility */ // 3 - extract ReloadableHtmlElement // 4 - clickOnceAndWait |
Done
Please check
Thanks
2018-05-11 10:07 GMT+03:00 Vihar Jambhulkar <notifications@github.com>:
… Can you share the code you are using also after clicking on downloading
button how are you making sure that the script is not terminated before the
complete downloading has been done.
Thanks,
On Thu, May 10, 2018 at 6:28 PM, slapadus ***@***.***>
wrote:
> Good day,
> I have encountered the same issue while automating some tests for
> documents downloading
> with Selenium 3.5.3 and Chrome 65.
> I have noticed that WebElement click() method randomly terminate without
> exception but no click is performed (so my files are never downloaded...)
> My solution was to implement a retry mechanism (loop until job is done or
> number of retries is reached)
> Any help ?
> Thanks
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/SeleniumHQ/selenium/issues/
4075#issuecomment-388045682>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/
AUJQTDcm12b7AAyVMVKJmE0WMLg_515Hks5txDmJgaJpZM4Nl_NU>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4075 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AlWHASf6I-vfvDna8xsQ2fpPMbbOUcLjks5txTijgaJpZM4Nl_NU>
.
|
We had the same problem with click sometimes doing nothing.
|
why not 1) wait for ajax queries to complete and 2) wait for java script readyState readyState should not be checked last ? |
def wait_until_page_load(self): |
Hi @vinaybond Regarding the below workaround that you provided, I have couple of points to ask you
Also if the first click is not working due to a real application issue say a bug in the app, wouldn't this be re-trying it multiple times and by chance if the re-attempt was successful, you would miss out on capturing that application bug ? Thanks, |
Hi @musanas |
Hi All! |
Hi All, |
I am also seeing the same issue. Fresh chrome instances seem to be fine but when reusing the same instance the click action seems to be very hit and miss. There are no errors and as far as selenium is aware it has performed the click but when you screenshot the result you can see nothing has happened (sometimes you see a highlight around the button or form element which suggests something has been attempted). For now the best workaround I have found is using javascript to click the button instead. Replacing click() with: (python)
As proven a lot more reliable and consistent in my cases. |
@mspilsbury Of course the downside to that approach is that it basically makes your tests meaningless since you're now potentially clicking on elements a user never could. |
Sorry I didn't provide a full detail of the solution just an example. The script call can still be used in conjunction with an element_to_be_clickable wait. This function still behaves correctly it is the actual click() function that does not seem to work all the time. I understand its not 100% ideal but as a solution right now, using the wait and the forcing the click via javascript works every time for me. |
Super noob here. Here is my code until thus far. driver = webdriver.Chrome() line[1]: |
OK, just found a solution from another resource. it clicks %100. (And also skips when the button is not active on the page) here is the code:
|
hi @opheno , |
Yea! The only solution is use |
This comment has been minimized.
This comment has been minimized.
Thanks for everyone's comments on this - very helpful. I've found element.click() is unreliable when testing Chrome desktop browser running in mobile emulation mode. I've written a JS helper function to workaround this issue where I'm replacing each instance of This is only supposed to be a temporary solution (it seems to work reliably for the latest version of Protractor) - hopefully a Selenium fix will turn up at some point :) Here's the function (hopefully others will find it useful)
|
@DanielFreemanTester No fix for that can come from Selenium - it's a bug in chromedriver/chrome - there have been a few reports of it to the chromedriver team and it has been open for quite a few months. It does not seem to be a priority to them. One example is - https://bugs.chromium.org/p/chromedriver/issues/detail?id=2452&q=emulation&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary |
Many thanks @twalpole , looks like the Chromium bug is receiving some attention as last updated just 4 days ago so hopefully this issue will get fixed soon :). |
It's stupid, but I thought I'd share this maybe it helps somebody. In my case it didn't work consistently because of an XPath element selector We were migrating from Selenium RC where old selectors were using XPath. Everything returned back to normal after replacing them with proper CSS selectors. |
Same issue, have you solved this problem right now? |
@jinliangwii , Yes this problem is solved with the solution mentioned by me. |
Hi |
the issue has already been submitted to ChromeDriver. Please use the Chromium tracker for followup. There is nothing selenium developers can do to fix this. |
OMFG! I was having the same problem... until I read the comment from @Edzarius, I'm using Safari with At the moment that I removed the |
Meta -
OS:
Windows/Linux (Cent OS & Ubuntu)
Selenium Version:
Any WebDriver version
Browser:
Chrome/Firefox and IE (Any version)
Expected Behavior -
Click operation should always work when no exception is thrown
Actual Behavior -
Click action works something and sometime it does not. It shows the element is actually being clicked, as for link and buttons we can see dotted border around the object. However the action on that click is not triggered. I tried .Click() / Actions Class/ Click using JS/ Press Enter button on element but none is working all the time.
Steps to reproduce -
I wish I could have provided the steps but this is happening on multiple webpages on click action. Many people around world is facing this issue. Save can be checked on stackoverflow or other forums. Element is present on the page and page is completely loaded when I took screenshot. I have seen this issue with Java and Python web drivers.
Suggestions & Observations -
I think selenium is sending the click but browser (IE/FF/chrome) are not ready to process it. May be its binding to JS is not done or something like that. If that is the case then is there a way selenium can find if the browsers are ready to perform click. I guess selenium already check for DOM status. Please see if anything else which can solve the problem
The text was updated successfully, but these errors were encountered: