element never gets visible for selenium python but works fine in slenium IDE

31 views
Skip to first unread message

Andrés Mauricio Gómez R

unread,
Oct 19, 2017, 12:18:24 PM10/19/17
to webdriver

i've been dealing with this for a few days and now i give up with searching and trying out

i'm writing a testCase with selenium, it's about a form that is hidden and after pressing some button it gets visible (using a bootstrap function "whatever.show()"). As i'm new with selenium the first thing i tried was make the testcase with seleniumIDE where everything worked fine, then exported to pyhon file, and when i attempt to excecute the script, it breaks saying that the element is not visible. i tried to wait until the element gets visible but never does. the function i tried for gets visible was

 try:
            element = WebDriverWait(driver, 10).until(
                EC.visibility_of_element_located((By.ID, "Email"))
            )
        finally:
            driver.quit()

there's something else, they have another panel with a input with id="Email" inside of it, but i tried to first get the panel to find the element, after clicked the button no panel gets visible for selenium despite when it's running i can see the panel visible after clicked the button

    terceroPanel = driver.find_element_by_id("divFormTercero")


    argosPanel = driver.find_element_by_id("divFormArgos")
    emailInput = argosPanel.find_element_by_id("Email")
    print(terceroPanel.is_displayed())
    print(argosPanel.is_displayed())
    print(emailInput.is_displayed())
    emailInput.clear()
    emailInput.send_keys("andresmaur...@gmail.com")

argosPanel is the panel of my interest, terceroPanel is the other one, the three console output are "False"

the complete code i tried last was

    driver.get(self.base_url + "/IngresosOnline/")
    driver.find_element_by_css_selector("#btnUserArgos").click()
    try:
        element = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, "Email"))
        )
    finally:
        driver.quit()

    terceroPanel = driver.find_element_by_id("divFormTercero")
    argosPanel = driver.find_element_by_id("divFormArgos")
    emailInput = argosPanel.find_element_by_id("Email")
    print(terceroPanel.is_displayed())
    print(argosPanel.is_displayed())
    print(emailInput.is_displayed())
    emailInput.clear()
    emailInput.send_keys("andresmaur...@gmail.com")

it breaks when send the keys. even i could see the input getting focus before throw the exception

Thanks a lot if someone can give me a hand with this.

here the HTML, the code is not mine, i'm testing the app of some partners

div class="col-md-12" id="divFormArgos" hidden>

<section id="loginFormArgos">
    <form action="/IngresosOnline/Account/Login" class="form-horizontal" method="post" role="form"><input name="__RequestVerificationToken" type="hidden" value="CwUxjXIIsx9b0IXeDhdb7FXlhTiMuYusRMvjZjG2KIXFfSi8lhC_4j19OXZKzU8bfffxY5d_1cmzigNUCcd78AJDf7_DZXGmhnQ_ayWWWks1" />                            <h4>Use una cuenta Argos para iniciar sesión.</h4>
    <hr />
        <div class="form-group">
            <label class="col-md-4 control-label" for="Email">Correo electr&#243;nico</label>
            <div class="col-md-8">
                <input class="form-control" data-val="true" data-val-email="El campo Correo electrónico no es una dirección de correo electrónico válida." data-val-required="El campo Correo electrónico es obligatorio." id="Email" name="Email" type="text" value="" />
                <span class="field-validation-valid text-danger" data-valmsg-for="Email" data-valmsg-replace="true"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-4 control-label" for="Password">Contrase&#241;a</label>
            <div class="col-md-8">
                <input class="form-control" data-val="true" data-val-required="El campo Contraseña es obligatorio." id="Password" name="Password" type="password" />
                <span class="field-validation-valid text-danger" data-valmsg-for="Password" data-valmsg-replace="true"></span>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <div class="checkbox">
                    <input data-val="true" data-val-required="El campo ¿Recordar cuenta? es obligatorio." id="RememberMe" name="RememberMe" type="checkbox" value="true" /><input name="RememberMe" type="hidden" value="false" />
                    <label for="RememberMe">&#191;Recordar cuenta?</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Iniciar sesión" class="btn btn-primary" />
                <a class="btn btn-danger" id="btnCancelar1">Cancelar</a>
            </div>

        </div>
        <br />
    </form> 
    </section>

darrell grainger

unread,
Oct 20, 2017, 3:00:43 PM10/20/17
to webdriver
Do you have the SeleniumIDE code that worked? If I understand the user scenario correctly it should be:
  1. Go to the website
  2. Click a button
  3. Wait for the form to be visible
  4. Fill out the form
Two things pop to mind for me. The first is that the element in the DOM you are clicking is NOT the element which triggers the event and makes the form visible. Seeing the HTML for the FORM does not help at all. Seeing the HTML for the button you click MIGHT help. But even then, it could be some javascript is tying an event to an element wrapping the button. Essentially, when I click a 'button' on the screen there could be multiple HTML elements in the same X,Y space on top of each other. The Z order will determine who gets the click first. For example, in the FORM you provided, clicking to put focus on the INPUT with id='Password' could be triggering an event associated with the SPAN under it, the DIV wrapping it or the DIV wrapping everything.

The second thing could be you aren't waiting for the right thing.

Without seeing the entire DOM it is hard to figure out what is going on. I can hide/show a FORM multiple ways. So there is no one solution because there isn't one implementation.

I'll look at the DOM around the button I'm clicking. I'll try clicking the button. See if that works. Because you are using python you can literally go to a shell prompt and enter `python`. This will put you at an interactive prompt, i.e. >>>>. Then you can start typing commands and see them execute in real time. You can copy and paste all the code from your project. Load the libraries, open the browser, go to the web page, etc.. Do everything up to the clicking of the button. Then you can start trying different Selenium commands to click things. Find the button and click it. Did the form appear. No? Try clicking the element which wraps the button. Keep doing this for a few things which wrap the button.

If that does not work, go to the browser, Inspect the button. Get the text in the button and search for it in the DOM. Does it appear twice? Once hidden and once visible? Maybe you are clicking the hidden instance. Figure out how you can click the correct element by using different selectors/locators.

If it is the second problem and clicking the button is working but the WebDriverWait is failing, you could enter everything but the WebDriverWait line in the interactive python shell. Then you can see if the element you are waiting for is visible (find the element then examine its attributes using get_attributes). If it is still invisible, try to figure out something else which is visible now but wasn't before you click the button.

Hope that helps,
Darrell


On Thursday, 19 October 2017 12:18:24 UTC-4, Andrés Mauricio Gómez R wrote:

i've been dealing with this for a few days and now i give up with searching and trying out

i'm writing a testCase with selenium, it's about a form that is hidden and after pressing some button it gets visible (using a bootstrap function "whatever.show()"). As i'm new with selenium the first thing i tried was make the testcase with seleniumIDE where everything worked fine, then exported to pyhon file, and when i attempt to excecute the script, it breaks saying that the element is not visible. i tried to wait until the element gets visible but never does. the function i tried for gets visible was

 try:
            element = WebDriverWait(driver, 10).until(
                EC.visibility_of_element_located((By.ID, "Email"))
            )
        finally:
            driver.quit()

there's something else, they have another panel with a input with id="Email" inside of it, but i tried to first get the panel to find the element, after clicked the button no panel gets visible for selenium despite when it's running i can see the panel visible after clicked the button

    terceroPanel = driver.find_element_by_id("divFormTercero")


    argosPanel = driver.find_element_by_id("divFormArgos")
    emailInput = argosPanel.find_element_by_id("Email")
    print(terceroPanel.is_displayed())
    print(argosPanel.is_displayed())
    print(emailInput.is_displayed())
    emailInput.clear()

    emailInput.send_keys("andresmauricio...@gmail.com")

argosPanel is the panel of my interest, terceroPanel is the other one, the three console output are "False"

the complete code i tried last was

    driver.get(self.base_url + "/IngresosOnline/")
    driver.find_element_by_css_selector("#btnUserArgos").click()
    try:
        element = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, "Email"))
        )
    finally:
        driver.quit()

    terceroPanel = driver.find_element_by_id("divFormTercero")
    argosPanel = driver.find_element_by_id("divFormArgos")
    emailInput = argosPanel.find_element_by_id("Email")
    print(terceroPanel.is_displayed())
    print(argosPanel.is_displayed())
    print(emailInput.is_displayed())
    emailInput.clear()

    emailInput.send_keys("andresmauricio...@gmail.com")
Reply all
Reply to author
Forward
0 new messages