0

I'm using the code below to replicate the action shown below. The script is able to select the field that has the text "operator maintenance" and click it using action chains, however, it only goes to the appropriate next page with the Employee ID field randomly.

ieOptions = webdriver.IeOptions()
ieOptions.add_additional_option("ie.edgechromium", True)
ieOptions.add_additional_option("ie.edgepath",'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')
ieOptions.ignore_zoom_level = True
driver = webdriver.Ie(executable_path='C:\Program Files (x86)\IEDriverServer.exe', options=ieOptions)

for key in parks:
    if PK == key:
        driver.get(parks[key][0])
        PW = parks[key][1]

# switch to selected iframe
driver.switch_to.frame('MWFApplicationFrame')
# Now continue with login process
UserName = driver.find_element(By.ID, "UserName")
UserName.send_keys(ID)
PassWord = driver.find_element(By.ID, "Password")
PassWord.send_keys(PW)
login = driver.find_element(By.ID, "Login")
login.click()
# switch to selected iframe
driver.switch_to.default_content()
emp = driver.find_element(By.ID, "menu").click()
driver.switch_to.frame('MWFPopupMenuFrame')
hoverable = driver.find_element(By.CLASS_NAME, "popupMenuCell")
ActionChains(driver)\
        .move_to_element(hoverable)\
        .click(hoverable)\
            .perform()

Manual flow:

enter image description here

Actual issue with script:

enter image description here

Html of webpage shown:

enter image description here

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
FallenEgg
  • 23
  • 5

1 Answers1

0

As the desired element is 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 either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.popupMenuFrame#MWFPopupMenuFrame")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "table.popupMenuMainTable table.popupMenuSubTable tr[screenName='Operator Maintenance'] > td"))).click()
      
    • Using XPATH:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='popupMenuFrame' and @id='MWFPopupMenuFrame']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='popupMenuMainTable']//table[@class='popupMenuSubTable']//tr[@screenName='Operator Maintenance']/td"))).click()
      
  • Note : You have to add the following imports :

     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352