I'm trying to login a website to web scrape its content with Selenium. The site has a virtual keyboard where the user inputs the password and I want to simulate the click on this keyboard.
Inspecting the site, that's the part where the keyboard is generated (the position of each key is randomly generated by a JavaScript, but that part is OK):
<div class="password-buttons">
<button class="button orange rounded" onclick="AddPsitions('8|9'); return false;" title="5 ou 3">
<span class="login-number">5</span>
<span class="login-or">ou</span>
<span class="login-number">3</span>
</button>
<button class="button orange rounded" onclick="AddPsitions('6|7'); return false;" title="8 ou 2">
<span class="login-number">8</span>
<span class="login-or">ou</span>
<span class="login-number">2</span>
</button>
<button class="button orange rounded" onclick="AddPsitions('4|5'); return false;" title="0 ou 6">
<span class="login-number">0</span>
<span class="login-or">ou</span>
<span class="login-number">6</span>
</button>
To simulate the click I'm doing the following (I also tried "//*[@title='0 ou 6']", without the '.'):
browser.find_element_by_xpath(".//*[@title='0 ou 6']").click()
But I'm getting this error:
Traceback (most recent call last):
File "webScrape_Rico.py", line 59, in <module>
browser.find_element_by_xpath(a).click()
File "/home/luciano/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 293, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/home/luciano/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/home/luciano/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/home/luciano/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: {" errorMessage":"Unable to locate an element with the xpath expression \".//*[@title='0 ou 6']\" because of the following error:\nError: TYPE_ERR: DOM XPath Exception 52","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"109","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:60775","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"xpath\", \"sessionId\": \"8ddb4f90-f6e6-11e6-9eb0-4ba40f4453e7\", \"value\": \"\\\".//*[@title='0 ou 6']\\\"\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/8ddb4f90-f6e6-11e6-9eb0-4ba40f4453e7/element"}}
I saw this options here: Find and click element by title Python Selenium
What am I missing here?