4

My test is failing with:

WebDriverException: Message: unknown error: Element is not clickable at point (1 786, 183). Other element would receive the click: <'div align="right">...<'/div>

xpath I access is:

${UPDATE}    xpath=//button[@type='submit' and contains(text(),'Update')]

use in keyword:

    wait until element is visible   ${UPDATE}
    click element    ${UPDATE}

source:

<div align="right">
    <button type="submit" class="btn btn-primary ng-binding" ng-click="submitForm()" ng-disabled="updateDisabled">Update</button>
    <button type="button" class="btn btn-primary" ng-click="reset(projectForm)" ng-disabled="updateDisabled">Reset</button>
</div>

But the button is really clicked in the test -> data are saved - so it is OK. I just don't understand why it throws the exception when it clicked correctly and what can I do to make it pass..It is just obvious that it found the element and clicked on it...I also tried to use "wait until element is enabled" and "focus"... Thanks for any suggestion! PS: I added the character "'" to div element in exception, otherwise it was not displayed here..:)

JeffC
  • 22,180
  • 5
  • 32
  • 55
neliCZka
  • 945
  • 1
  • 16
  • 27
  • What webdriver (browser) are you using? – Goralight Dec 08 '16 at 18:56
  • try by adding some delay using `sleep 1s` – Sarada Akurathi Dec 09 '16 at 05:42
  • i am using chromedriver and sleep is not a se2lib and my "wait until element is visible" is passing, so it should not be the case I think – neliCZka Dec 09 '16 at 08:34
  • You are right, Sleep is not a Sel2Lib keyword. It is a built in one. However, you can still use it. I have had this issue before with Chrome (Hence why I asked what your browser was) – Goralight Dec 09 '16 at 09:07
  • Hm I was wondering why the "sleep" was not highlighted..because I tried it..did not help when I had it just before click, seems it now works when I added the sleep also after click – neliCZka Dec 09 '16 at 09:15
  • If you copied it directly from @SaradaAkurathi example, then its because it was not syntax correct, needed to have at least 1 more space between the sleep and the 1 :) – Goralight Dec 09 '16 at 09:17
  • I had correct syntax..just the sleep before click didn't make any difference.. – neliCZka Dec 09 '16 at 09:19
  • Oh right sorry, i misread what you typed, sorry. Yeah it wouldnt do. Basically what i did was by placing an abundant amount of sleeps, you can visually see what your driver is doing - seeing what passes and what slips up. The previous sleeps I know would not do anything. But I did it to show you. It is to do with the driver being too quick (I think, dont quote me) and it trips over yourself. By adding the sleep, you forced it to take a breather for 1s. – Goralight Dec 09 '16 at 09:22

5 Answers5

1

Although it is really bad practise to do this, I would recommend placing a couple of Sleep 1s keywords around your test case, for example:

Sleep    1s
Wait Until Element Is Visible   ${UPDATE}
Sleep    1s
Click Element    ${UPDATE}
Sleep    1s

Just to debug and make sure the driver isn't tripping over itself. (Which was the issue I was having) If this then works and passes, you will then need to basically wait longer than the button being active. Is there another section of the webpage which takes longer to load? If so use that.

But when you can, get rid of the Sleep 1s Key words as it is really bad practise.

Goralight
  • 2,067
  • 6
  • 25
  • 40
  • hmm the last sleep (after click) really makes the difference..now it passes..but it is weird and as you said, not a good practice..but thank you because it seems there is now other option perhaps.. – neliCZka Dec 09 '16 at 09:17
  • Ok so now you know where the problem lies, something to do after the Click Element. Perhaps switching to Click Button? (Not sure thatll do anything but worth a shot) or perhaps trying to make it wait after the button is pressed? Bottom line is you now know where the problem is and can work with it :) – Goralight Dec 09 '16 at 09:19
  • yes, now I removed also the sleep before click and left just the one after click and it passes..probably if I do another action in the test (after click) with "wait until" for another element, it could be solved as well so probably I'll be able to remove the sleep.. – neliCZka Dec 09 '16 at 09:22
  • Exactly, you need to find a way to slow it down without using sleep. Use sleep if you absolutely have to.. If you ever run into trouble i would recommend using this sleep technique as it really helps with debugging. – Goralight Dec 09 '16 at 09:23
0

I am using the following approach.

  1. located an element which is visible after the page is fully load.
  2. get it's xpath

Use the following keywords:

Wait Until Keyword Succeeds  Page Should Contain Element  ${Xpath}
Click Element  ${Element}

This will help you to avoid using sleeps in your testcases.

Richard Zilahi
  • 673
  • 2
  • 12
  • 25
0

How about: wait until element is visible ${UPDATE} mouse down ${UPDATE} mouse up ${UPDATE}

Worked for me for some weird acting elements..

becixb
  • 365
  • 1
  • 9
0

There are instances when Wait Until Element Is Enabled and Wait Until Element Is Visible will return true but the element will still not be clickable, because it is hidden/overlapped by another element.

I can repoduce this situation in my app. An error I get is:

ElementClickInterceptedException:
Message: element click intercepted:
Element <button>...</button> is not clickable at point (169, 286). Other element would receive the click: <div></div>

There doesn't seem to be any "smart" solution without writing an external library. For now, the best way is to use this:

*** Keywords ***
Click Element Wait
    [Arguments]    ${locator}=required    ${timeout}=2    ${mustWait}=False
    Wait Until Element Is Visible    ${locator}    ${timeout}
    Wait Until Element Is Enabled    ${locator}    ${timeout}
    Run Keyword If    $mustWait == True    Sleep    1s
    Click Element    ${locator}

Use it like this:

Click Element Wait    myButton    4    True    # Wait until element is visible & enabled, then another 1 second as well
Click Element Wait    myButton    # Just wait until element is visible & enabled
dǝɥɔS ʇoıןןƎ
  • 1,674
  • 5
  • 19
  • 42
0

Richard's answer was very helpful but might not have been directly applicable for everyone. I had to customize it to my use case -

Wait Until Keyword Succeeds      5x     10s      Click Element   XPATH://<add xpath>

This would run the test 5 times with a 10s interval in between failures absolutely removing the need for any explicit sleeps to be made in the code. Both the values can be altered to suit you needs better. Note that the Wait Until Keyword Succeeds keyword can be used along with any operation including Input Text which means that if you change every line of your test case to use this, you can guarantee that your tests will pass irrespective of variations in response times of the website.