Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript Multiple Select with Selenium

Javascript Multiple Select with Selenium

Scheduled Pinned Locked Moved Web Development
questionjavascriptpythonhtmltesting
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ibrahim Bello
    wrote on last edited by
    #1

    Hi, I am testing a webpage using selenium. I want to select all the items in a multi-select listbox. It seems selenium doesn't provide a "select all items" function even though it has an "unselect all items". I have been unable to use the add_selection function for this purpose. I write a javascript code to select all the items using eval_script(). I'm using python.

    script = """
    multiselect = document.getElementsByTagsName("name");
    alert(multiselect);
    """

    The alert statement above displays that the object is an HTML Collection. Interestingly alert(multiselect.length); returns "0" even though I'm sure that the list is populated. This makes multiselect.item(2) for example to evaluate to "undefined". To select all the items I'm simply using:

    script = """
    for(var k = 0; k < multiselect.length; k++)
    {
    multiselect.item(2).selected = true;
    }
    """

    I run the script by simply: sel.eval_script(script). How do I get around this? Is Javascript the best way? Thanks :)

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups