Saltar al contenido

~ / archivo / stackoverflow / 50805168

Cannot identify element in splinter browser

StackOverflow · python, selenium-webdriver, splinter · ayudé respuesta aceptada
  1. DrBug pregunta 2018-06-11 19:58

    I have the following snippet of HTML

    <input type="text" name="fldLoginUserId" maxlength="15" size="10" onkeypress="return fSubmit(event);" value="" class="input_password">
    

    This is part of the larger HTML. This element which I can see using Chrome - Inspect is available. However, when I try something like

    myurl = 'xxx' # I am hiding xxx as I dont want to disclose the site here
    
    from splinter import Browser
    
    browser = Browser('chrome', **executable_path)
    browser.visit(myurl)
    customerId = browser.find_by_name('fldLoginUserId')
    

    This returns customerId as a empty list.

    Can someone please point any mistake I am making ?

    • JeffC 2018-06-11 21:09 Is the element in an IFRAME? Have you tried using $$() and $x() in the dev console to test your locators?
  2. Miguel Ortiz yo respuesta aceptada +1 2018-06-11 21:15

    This is my first time using Splinter with python here. Your code seems to work:

    #!/usr/bin/python
    
    from splinter import Browser
    browser = Browser('chrome')
    browser.visit('http://migueleonardortiz.com.ar')
    customerId = browser.find_by_name('generator')
    for objectx in customerId :
          print objectx._element.get_attribute('content')
    

    Output:

    mortiz@florida:~/Documents/projects/python/splinter$ python web_browser_splinter.py 
    Divi v.2.5.6
    WordPress 4.9.6
    

    When I've asked for a non-existing value in the HTML the output is an empty list:

    mortiz@florida:~/Documents/projects/python/splinter$ python web_browser_splinter.py 
    []
    

    I've tracked your property to the site that you're probably using. That HTML is being rendered by Javascript:

    document.write('<input type="text" name="fldLoginUserId" maxlength="15" size="13" autocomplete="off" onkeypress = "return fSubmit(event);" value="" oncopy="return false" ondrag="return false" ondrop="return false" onpaste="return false" />')
    

    And although the property exists in the HTML inspection it can't be retrieved the same way than the example I provided.

    Because it's being rendered by Javascript, I guess it's something related to that and the DOM loading order.

    Just a guess, maybe a good point to start.

← todos los hilos de StackOverflow