2

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

2
  • just double checking, is the error thrown by the object.click() line? Commented Aug 20, 2020 at 17:40
  • 1
    Hi, @M Z, yeah the error is in the line object.click(). If you want to try this is the url: sucursalempresas.transaccionesbancolombia.com/SVE/control/… Commented Aug 20, 2020 at 17:43

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Just beware... in general, you wouldn't want to use this method if your script was being used to test the site because this method shortcuts the UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.