1

Context: I'm writing a Python script to ultimately download postings on the following site (https://ngc.taleo.net/careersection/ngc_pro/jobsearch.ftl?lang=en&_ga=2.59113261.1016801192.1577482911-1938918126.1574124672). I've been able to programmatically navigate the page to search for a keyword, click the search button and drop down a filter field for location.

Questions: I've been unable to write the logic to find the california checkbox under the location element. Can someone take a look at the page source snippet below and help me find the correct logic to click on the corresponding california location checkbox element?

Here's a snippet of the page source surrounding the checkbox:

<div id="fieldSetId-LOCATION-level-2" class="hidden-audible">State / Province</div><div id="LOCATION-level-2" class="filter-level-title">State / Province</div><input id="LOCATION-level-2-item-0" type="checkbox" name="2160420105" title="California" class="filter-checkbox"><div class="label-wrapper"><a><label for="LOCATION-level-2-item-0" class="checkbox-label"><div class="checkboxp checkbox-unchecked">&nbsp;</div><span class="valuesdiv"><span class="filter-text">California</span><span class="filter-quantity">(48)</span></span></label></a></div><input id="LOCATION-level-2-item-1" type="checkbox" name="2660420105" title="Maryland" class="filter-checkbox"><div class="label-wrapper"><a><label for="LOCATION-level-2-item-1" class="checkbox-label"><div class="checkboxp checkbox-unchecked">&nbsp;</div><span class="valuesdiv"><span class="filter-text">Maryland</span><span class="filter-quantity">(42)</span></span></label></a></div><input id="LOCATION-level-2-item-2" type="checkbox" name="2360420105" title="Virginia" class="filter-checkbox"><div class="label-wrapper"><a><label for="LOCATION-level-2-item-2" class="checkbox-label"><div class="checkboxp checkbox-unchecked">&nbsp;</div><span class="valuesdiv"><span class="filter-text">Virginia</span><span class="filter-quantity">(41)</span></span></label></a></div>

Here's a snippet of the Python script I have so far:

from selenium import webdriver

#Navigate to the main job search page 
#https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca
browser = webdriver.Firefox(executable_path=r'C:\Users\etherealessence\AppData\Local\Programs\Python\Python36\geckodriver-v0.26.0-win64\geckodriver.exe')
browser.get(r'https://ngc.taleo.net/careersection/ngc_pro/jobsearch.ftl?lang=en&_ga=2.59113261.1016801192.1577482911-1938918126.1574124672')

#Fill in the "keyword" search input
keyword_element = browser.find_element_by_id('KEYWORD')
keyword_element.send_keys('SQL')

#Find search button and click
submit_button = browser.find_element_by_id('search')
submit_button.click()

#Drop down location field 
location_field = browser.find_element_by_id('LOCATION-link')
location_field.click()

Fyi this is my first time using selenium so please be kind.

1 Answer 1

2

To click on the checkBox California . You Induce WebDriverWait() and element_to_be_clickable() and following xpath.

To click on location you need to scroll to element by using location_once_scrolled_into_view and then click on that.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver.get("https://ngc.taleo.net/careersection/ngc_pro/jobsearch.ftl?lang=en&_ga=2.59113261.1016801192.1577482911-1938918126.1574124672")
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"KEYWORD"))).send_keys('SQL')
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"search"))).click()
element=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[@id='LOCATION-link' and text()='Location']")))
element.location_once_scrolled_into_view
element.click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[.//span[text()='California']]//div[@class='checkboxp checkbox-unchecked']"))).click()

Browser Snapshot:

enter image description here

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.