0

Currently I am trying to click the "entry-level" link in an iframe, for this website:https://a127-jobs.nyc.gov/index_new.html?category=CAS

Unfortunately, the url does not change if I click entry level, so therefore I am forced to automate.

I am not sure what to do, if the problem is that I have entered the wrong iframe? there seems to be only one, but I could be wrong.

from selenium import webdriver
import time

#webdriver
driver = webdriver.Firefox(executable_path="/Users/alexandrubordei/Desktop/geckodriver")

#get the website
driver.get ("https://a127-jobs.nyc.gov/index_new.html?category=CAS")

time.sleep(10)

#switch to iframe
iframes = driver.find_elements_by_tag_name("iframe")

driver.switch_to.frame(iframes[0])

time.sleep(10)

#click element "entry level"
driver.find_element_by_xpath('//*[@id="ti_S13"]').click()

When I run my code everything seems to function, except the link is not clicked. My search results are not narrowed.

However I do not get any errors. I get an error as:

Process finished with exit code 0
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • first try this `count = driver.find_elements_by_xpath('//*[@id="ti_S13"]').click() ` print `len(count)`. If it is zero, that means either there's no elements with the used locator. – Kushal Bhalaik Jan 08 '19 at 07:38

2 Answers2

0

you have to click the a element inside that ID

driver.find_element_by_xpath('//*[@id="ti_S13"]/a').click()
ewwink
  • 18,382
  • 2
  • 44
  • 54
0

To click() on the element with text as entry-level as the the desired elements are within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • You can use the following solution:

    • Code Block:

      from selenium import webdriver
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      from selenium.webdriver.common.by import By
      
      driver = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
      driver.get("https://a127-jobs.nyc.gov/index_new.html?category=CAS")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='ptifrmtgtframe' and @name='TargetContent']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Entry-Level"))).click()
      
  • Browser Snapshot:

entry_level

Here you can find a relevant discussion on Ways to deal with #document under iframe

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you I will try this out, however I am curious: I am using Firefox as my web driver as I had some issues with Chrome. Is there anything major that I would have to change in the code you provided to do this? – AlexNeedsHelp Jan 08 '19 at 09:51
  • This solution should work cross browser and cross platform. In-case of _Firefox_ you simply need to take out the `ChromeOptions` parts. However I have updated my answer as per your specifications. – undetected Selenium Jan 08 '19 at 09:59
  • Ahhahaha, well just wait because I might just be on here everyday with a new question – AlexNeedsHelp Jan 09 '19 at 18:58