Python Selenium javascript error: shape=rectangle is not supported

Viewed 186

I'm using python selenium to automate the download of financial reports. To achieve this I have to insert my password using this virtual keyboard:

enter image description here

I'm trying to click every letter of my password through xpath:

object = driver.find_element_by_xpath('//*[@id="alphaKeyboard"]/area[13]')
object.click()

The XPath to each letter is quite similar, only changes the number inside *area[]*

But I'm getting the following error:

selenium.common.exceptions.JavascriptException: Message: javascript error: shape=rectangle is not supported

I suppose this problem is related to the shape='rectangle' element that contains the virtual keyboard, the complete html element for each letter looks like this, for example for the letther 'F':

<area shape="rectangle" coords=" 72, 22, 93, 44" onclick="writeAlpha('F')" onmouseover="setHandCursor(document.alphaKeyboard)" onmouseout="setDefaultCursor(document.alphaKeyboard)">

Any suggestions with that?

I let you the URL if you want to try:

https://sucursalempresas.transaccionesbancolombia.com/SVE/control/BoleTransactional.bancolombia

1 Answers

There's a big shortcut for you on this one.

In your element, you have:

onclick="writeAlpha('F')"

On click that runs the javascript function writeAlpha('F'). You can run that function directly and not have to worry about the keyboard or xpaths at all.

Running it from the devtools console looks like this:

Devtool Keypress

In python you run javascript as such:

driver.execute_script("writeAlpha('F')")

You'll just need to update the letter to send.


[Update] - Taking it a little further...

You can create your details as string, split it and send it with a loop like this:

driver = webdriver.Chrome()
driver.get("https://sucursalempresas.transaccionesbancolombia.com/SVE/control/BoleTransactional.bancolombia")

myKeys = "HELLOWORLD"
myKeys = myKeys.split()

for key in myKeys:
    driver.execute_script("writeAlpha('"+key+"')")

That outputs this:

final keys to virtual keyobard

Related