-1

Using the RobotFramework, I need a click using 'Execute Javascript' which is more on the right side located.

What I have so far is this:

${ele}    Get WebElement    //input[@id='halfButton']
    Execute Javascript    arguments[0].click();     ARGUMENTS    ${ele} 

How can I change it so it clicks on the right?

ouflak
  • 2,458
  • 10
  • 44
  • 49
LTL
  • 339
  • 1
  • 9
  • What do you mean by "more on the right side located"? – Emil Karlsson Oct 01 '21 at 11:53
  • 1
    Could this work for you? [How to simulate a click by using x,y coordinates in JavaScript?](https://stackoverflow.com/questions/3277369/how-to-simulate-a-click-by-using-x-y-coordinates-in-javascript) – Peter Krebs Oct 01 '21 at 12:06
  • So how would that look like in my code? javascript is not my thing – LTL Oct 01 '21 at 12:25
  • I tried this: EXECUTE JAVASCRIPT arguments[0].click({ button: 1, x: 1500, y: 10 }) ARGUMENTS ${ele} ... but I can't see where it clicks. – LTL Oct 01 '21 at 12:26
  • If you have access to a JavaScript execution context, why are you clicking at an arbitrary coordinate? Why not invoke the click function on the element itself? – esqew Oct 01 '21 at 12:42
  • @esqew https://obstaclecourse.tricentis.com/Obstacles/41038 – LTL Oct 01 '21 at 12:43
  • There is a progress in this series of questions LTL, bravo; specific, and on the point. – Todor Minakov Oct 01 '21 at 16:14

3 Answers3

1

Without spelling out the solution line by line, here's the algorithm - when Selenium makes a click, it does so in the dead center of the object. That's the "catch" in this Tosca challenge - they want you to position the click to the right of that - and you have to calculate where.

SeleniumLibrary to the rescue - get the position of the button, then get its width (you need a quarter of it, more or less); then do some simple math to calculate a position to the right from its center - and click at those coordinates.

Todor Minakov
  • 19,097
  • 3
  • 55
  • 60
0

Somehow the calculations don't seem to work....

So I tried a hail shotgun method:

 CLICK ELEMENT AT COORDINATES    id=halfButton    600    100
    LOG TO CONSOLE    1
    CLICK ELEMENT AT COORDINATES    id=halfButton    600    150
    LOG TO CONSOLE    2
    CLICK ELEMENT AT COORDINATES    id=halfButton    600    100
    LOG TO CONSOLE    3
    CLICK ELEMENT AT COORDINATES    id=halfButton    610    100
    LOG TO CONSOLE    4
    CLICK ELEMENT AT COORDINATES    id=halfButton    620    100
    LOG TO CONSOLE    5
    CLICK ELEMENT AT COORDINATES    id=halfButton    630    100
    LOG TO CONSOLE    6
    CLICK ELEMENT AT COORDINATES    id=halfButton    560    100
    LOG TO CONSOLE    7
    CLICK ELEMENT AT COORDINATES    id=halfButton    570    150
    LOG TO CONSOLE    8
    CLICK ELEMENT AT COORDINATES    id=halfButton    580    100
    LOG TO CONSOLE    9
    CLICK ELEMENT AT COORDINATES    id=halfButton    590    100
    LOG TO CONSOLE    10
    CLICK ELEMENT AT COORDINATES    id=halfButton    520    100
    LOG TO CONSOLE    11
    CLICK ELEMENT AT COORDINATES    id=halfButton    530    100

Still it didn't hit the target.

I know the viewport is: 1366 by 643 (1374, 586) is out of bounds of viewport width (1366) and height (643), which was tried by x-700 x y-100.

  1. If it is not outside of viewport, I actually miss some kind of feedback "tried at location x and y".
  2. Is the x and y from the centre of the element or from the left top of the viewport?
  3. It is not visible to see where the element is clicked... I mean there's not any kind of mousetrail/mousehit location to see.
ouflak
  • 2,458
  • 10
  • 44
  • 49
LTL
  • 339
  • 1
  • 9
0

You can move a lot on the X horizontal axis, but you can't move a lot on the Y vertical axis, because the button is not very high.

therefor this worked:

 CLICK ELEMENT AT COORDINATES    id=halfButton    100    1
    LOG TO CONSOLE    1
LTL
  • 339
  • 1
  • 9