Click on button does not work

Asked

Viewed 1,323 times

0

I have a button made on ext, that he should open a window when Selenium clicked, but that doesn’t happen, I’m doing it this way.

    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 missing? already tried by name, id.. none works

  • Good afternoon, please post a code that can be read this: http://answall.com/help/mcve - I hope you understand as a constructive criticism,

  • Already had a piece of code, but anyway added what is needed.

  • 1

    This driver.find_element_by_class_name(' x-form-file-input') shouldn’t be this driver.find_element_by_class_name('x-form-file-input') (spaceless)?

  • the name of the button is with spacing

1 answer

1


I believe the event:

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

Should be called that .click() and the method find_element_by_class_name search tags with attribute class and not name or id.

Using the method class_name

You should keep in mind that both Javascript and HTML as anything that understands the DOM attribute class="" works TOTALLY different from other attributes, search for class_name is different from normal attributes, the argument in the method find_element_by_class_name cannot contain spaces, it must be so:

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

It takes elements that contain the string between spaces, it will "catch" 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 attribute name="" thus:

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

You must do so:

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

Picking up element by id=""

If what you want is the attribute id="" thus:

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

You must do so:

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

Taking 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 take it by 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 he considers an Robothic action and blocks it, so instead, use the send_keys thus:

  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:");

Follows the documentation:

  • <id="fileuploadfield-1033-button-fileInputEl" data-ref="fileInputEl" class=" x-form-file-input" type="file" size="1" name="file" role="button" componentid="fileuploadfield-1033-button">

  • I edited as examples of inputs, check there and see if it was clear the use of the attribute class="" @Guilhermelima and let me know if something fails ;)

  • 1

    guy really you’re right...I figured out what happens, he clicks on the button but doesn’t open the window doesn’t open.. knows what can be?

  • it opens a windows upload file

  • :(, It complicated my situation, in the Tb?

  • @Guillhermelima makes a test 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:"); and let me know

  • Attributeerror: 'Webelement' Object has no attribute 'Sendkeys'

  • @Guilhermelima I edited the comment is send_keys

  • 1

    Man, congratulations worked. I don’t know how to thank :D

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.