1

I am trying to automate the login procedure with Selenium in Firefox with Python.

That's how a login button looks like in HTML:

<td>
  <input name="cmd" value="lg" type="hidden">
  <input src="ok.png" style="border-style: none;" type="image">
</td>

I have tried a following method:

loginButton = driver.find_elements_by_xpath("//input[@name='cmd' and @value='lg']")[0]
loginButton.click()

It returns the following exception with an empty message.

"selenium.common.exceptions.ElementNotInteractableException: Message: "

This method returns

"Message: Element is not visible"

loginButton = driver.find_element_by_name("cmd")
loginButton.send_keys(Keys.RETURN)

Could you please explain what I am missing?

Andersson
  • 51,635
  • 17
  • 77
  • 129
Andrey Mazur
  • 510
  • 4
  • 14
  • The input is hidden, how is selenium then supposed to click it? Selenium emulates a user who would not be able to click it either – Metareven Nov 20 '18 at 08:23
  • There is another input which is not hidden, but without the name and value, and it lays exactly on the hidden input. Sorry that I haven't mentioned it. – Andrey Mazur Nov 20 '18 at 08:26
  • Then you should try clicking that one instead of the hidden one. Selenium will fail if it tries to click an element and something else is in the way – Metareven Nov 20 '18 at 08:28
  • That's my problem, I cannot find the way how to get the access to an "input" which has only source, style and type. Webdriver has not function "driver.find_element_by_type("input")" – Andrey Mazur Nov 20 '18 at 08:31
  • 1
    Why not just use a regular css selector? I use CSS-selectors for everything as I think the code becomes more uniform. You could also use the xpath-selector you wrote up there if you just remove the name and value stuff. I am not that good with xpath-selectors, but I assume it will select the first input on the page, just as a css-selector would – Metareven Nov 20 '18 at 08:34

1 Answers1

1

If you want to click on input next to hidden, try

loginButton = driver.find_element_by_xpath("//input[@src='ok.png']")
#  loginButton = driver.find_element_by_xpath("//input[@name='cmd' and @value='lg']/following-sibling::input")
loginButton.click()
Andersson
  • 51,635
  • 17
  • 77
  • 129