Click button does not work [closed]

0

I have a button made in ext , that it should open a window when Selenium clicked, but it does not happen, I'm doing it as follows.

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    import unittest

    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.get("mywebsite")

    def ClickFunction(self):
            driver = self.driver
            driver.find_element_by_class_name(' x-form-file-input').click


    if __name__ == '__main__':
        unittest.main()

cmd does not return errors.

Ran 1 test in 5.580s

OK

Where can I be wrong? already tried for name, id .. none works

    
asked by anonymous 13.01.2016 / 18:01

1 answer

1

I believe the event:

driver.find_element_by_class_name(' x-form-file-input').click

It should be called .click() and the find_element_by_class_name method looks for tags with the class attribute and not name or id .

Using the method class_name

You should keep in mind that in both Javascript and HTML, as well as anything that understands the DOM, the class="" attribute works FULLY different from the other attributes, searching for class_name is different from normal attributes, / strong> in method find_element_by_class_name can not contain spaces , it should look like this:

driver.find_element_by_class_name('x-form-file-input')

It takes elements that contain the string between spaces, it will "get" elements like:

<input class="x-form-file-input">
<input class="abc x-form-file-input">
<input class="x-form-file-input def">
<input class="abc x-form-file-input def">
<input class=" x-form-file-input "> (veja aqui tem espaço no começo e no fim e será pega também)
<input class=" x-form-file-input"> (veja aqui tem espaço no começo e será pega também)
<input class="x-form-file-input "> (veja aqui tem espaço no fim e será pega também)

Taking element by attribute name=""

If what you want is the name="" attribute like this:

<input name="x-form-file-input"></input>

You should do this:

  driver.find_element_by_name('x-form-file-input').click()

Picking element by id=""

If what you want is the id="" attribute like this:

  <button id="x-form-file-input"></button>

You should do this:

  driver.find_element_by_id('x-form-file-input').click()

Picking element by a CSS selector

You can also use by CSS selector which is more advanced:

driver.find_element_by_css_selector("div.content .class")

Or get an ID:

driver.find_element_by_css_selector('#foo')

Opening the dialog window with send_keys

In browsers it is not allowed to use Click without the user, when you call .click it considers a robotic action and blocks it, so instead use send_keys like this:

  driver.find_element_by_class_name('x-form-file-input').send_keys("/");

Or so:

driver.find_element_by_class_name('x-form-file-input').send_keys("C:");

Follow the documentation:

13.01.2016 / 18:28