0

Hey im using python selenium to download data from table. But when im want to prepare data i cant select a checkbox 'toggle all'....

im geting on page:

browser.get("https://gold.jgi.doe.gov/studies?setColumns=yes&Organism.NCBI+Taxonomy+ID=%3D500633")

click 'select columns for table'

browser.find_element_by_xpath('//*[@id="showColsButton"]').click()

and here we are checkbox ;toggle all'...

browser.find_element_by_xpath('//*[@id="selectFieldsList"]/thead/tr[2]/td/input').click()

Realy tryed xpath, css selector....

and here we are html fragment:

<table class="selectFieldsList" id="selectFieldsList">

<thead>
        <tr><td colspan="2" align="center">
        Select Fields using the Checkboxes<br>
        <input type="submit" value="Submit" name="fieldSubmit" id="submitMe" class="submitMe">
    </td></tr>


 <!--  add a select all option -->
       <script language="JavaScript">
       function toggle(source) {
           checkboxes = document.getElementsByName('selectField');
           for(var i=0, n=checkboxes.length;i<n;i++) {
              checkboxes[i].checked = source.checked;
           }
       }

       </script>
       <tr><td> <input type="checkbox" onclick="toggle(this)"> Toggle All<br> </td></tr>
<tr><td>* = required column</td><td>&nbsp;</td> </tr>

<tr><td> <input type="button" id="entityFieldSelectorToggle" value="Expand All Fields"> </td>
</tr></thead>
<tbody>
6
  • What version of python? What version of Selenium bindings? Commented Mar 22, 2017 at 20:10
  • python 3.5 and selenium 3.0.2 Commented Mar 22, 2017 at 20:15
  • Hmm, I'm using OS X (10.11.6), Python 3.6, Selenium 3.3.1, and geckodriver to instantiate a Firefox (51.0.1 64-bit) browser window. When I run your code, the "Toggle All" box is checked. Is that the desired effect of the code? Commented Mar 22, 2017 at 20:22
  • I will check the software ;p Commented Mar 22, 2017 at 20:34
  • 1
    ok i solved it xD, I give 5 seconds sleep and it work :) Commented Mar 22, 2017 at 20:39

1 Answer 1

3

Instead of using sleep use explicit wait is good practise, because it will same 5 sec of time even after element is found. Hope it will be useful to you

 from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    driver.get("https://gold.jgi.doe.gov/studies?setColumns=yes&Organism.NCBI+Taxonomy+ID=%3D500633")
    driver.find_element_by_xpath('//*[@id="showColsButton"]').click()
    wait = WebDriverWait(driver, 10)
    element = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="selectFieldsList"]/thead/tr[2]/td/input')))
    driver.find_element_by_xpath('//*[@id="selectFieldsList"]/thead/tr[2]/td/input').click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.