-2

Using Selenium in Python, I am trying to write a function that, based on a company name, employee first name, and last name, does the following:

  1. Goes to this website: https://dwcdataportal.fldfs.com/Exemption.aspx
  2. Fills in the company name, employee first name, and last into their respective fields (leaving “Federal Employer ID Number” blank and keeping “Construction/Non-Construction” as its default value “All”)
  3. Searches based on that information
  4. Returns true if records are found and false if not

Can anyone help with building this?

Here is the starting framework for the code:

from selenium import webdriver
driver = webdriver.Chrome('driver_location')
def owner_exemption(company_name, employer_first_name, employer_last_name):
    # The above code would go here

Thank you in advance for your help.

swp1
  • 5
  • 1
  • 6

2 Answers2

0

Here's a start on how to go to the site and then proceed to wait for the elements to be able to send keys. It also hits the search button for you to go to the next page. Now to get the proper xpath you go into the developer console and inspect the element you want and right click copy the selector.

wait=WebDriverWait(driver, 10)
url ="https://dwcdataportal.fldfs.com/Exemption.aspx"
driver.get(url)
def owner_exemption(company_name, employer_first_name, employer_last_name):
    # The above code would go here
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ContentPlaceHolder1_txtLastName"))).send_keys(employer_last_name)
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ContentPlaceHolder1_txtFirstName"))).send_keys(employer_first_name)
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ContentPlaceHolder1_lblEmployerName"))).send_keys(company_name)
    wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ContentPlaceHolder1_btnSearch2"))).click()
    try:
        wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#ContentPlaceHolder1_lblNotFound")))
        return True
    except:
        return False
    
    
print(owner_exemption('aaa','aaa','aaa'))

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32
0

To fill in the company name, employee first name, and last into their respective fields (leaving “Federal Employer ID Number” blank and keeping “Construction/Non-Construction” as its default value “All”) within the page https://dwcdataportal.fldfs.com/Exemption.aspx you have to induce WebDriverWait and you can use either of the following Locator Strategies:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    options = Options()
    options.add_argument("start-maximized")
    driver = webdriver.Chrome(executable_path=r'C:\WebDriver\ChromeDriver\chromedriver.exe', options=options)
    driver.get('https://dwcdataportal.fldfs.com/Exemption.aspx')
    
    def exemption_search(company_name, employer_first_name, employer_last_name):
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[title='Enter Employer Name']"))).send_keys(company_name)
        driver.find_element(By.CSS_SELECTOR, "input[title='Enter First Name']").send_keys(employer_first_name)
        driver.find_element(By.CSS_SELECTOR, "input[title='Enter Last Name']").send_keys(employer_last_name)
        driver.find_element(By.CSS_SELECTOR, "input[value='Search']").click()
    
    exemption_search("swp1", "swp2", "swp3")
    
  • Browser Snapshot:

dwcdataportal

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352