Reputation: 945
I need to be able to click on more clickable elements which are a part of an SVG chart.
I am able to click on any of the bar separately, but I also have to select more than one of them, and then click another link which opens the data in another view for all the selected items, altogether.
I wanted to do it in a loop, something like
Press key ${BAR ELEMENT} CTRL
and then do the click on the last entry. But I keep getting this error for Press Key keyword:
WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)
Even if I put FOCUS ${BAR ELEMENT}
before the Press key
, it throws the same error.
Clicking on the ${BAR ELEMENT}
works with no problem (even in the loop).
Also, I am not even sure if CTRL can be used (or maybe it is CONTROL or I have to use ASCII code), but I would like to find out. It's just that I can't get even to this step, so does anyone have any ideas to help?
It would be better to have possibility to press and hold CTRL key independently from the element, because in this case it does not really make sense to focus element to hit CTRL, but Press key
can't be used without locator.
I have attached a picture of the bars I need to click on (blue) for reference:
Upvotes: 1
Views: 1502
Reputation: 945
So I found out solution:
I prepared python functions to hold ctrl and release ctrl
def hold_ctrl(self):
self.get_action_chain().key_down(Keys.LEFT_CONTROL)
self.get_action_chain().perform()
def release_ctrl(self):
self.get_action_chain().key_up(Keys.LEFT_CONTROL)
self.get_action_chain().perform()
And then I used it out of the loop in which I performed the clicks:
some code before..
hold ctrl
:for ${value} IN @{list}
\ wait until element is visible ${BARS}
\ ${bar_xpath}= bar of specific value ${BARS} ${value}
\ wait until element is visible ${bar_xpath}
\ click element ${bar_xpath}
release ctrl
release ctrl
${bar_xpath}= bar of specific value ${BARS} ${value}
click element ${bar_xpath}
Only weird thing is that I have to use release ctrl
twice otherwise it does not work...
Upvotes: 3