Python selenium locate element in multiple iframes

后端 未结 2 539
说谎
说谎 2021-01-24 23:57

I am new to Selenium for Python and was trying to locate element in multiple iframes. This is the DOM element I can see.



        
2条回答
  •  旧巷少年郎
    2021-01-25 00:18

    As per the HTML you have shared to retrieve the id of the body tag of the second child you can use the following code :

    # Switch to the first iframe
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@src='BuyFlow.aspx']")))
    
    # Fill in Address and ZipCode inputbox and submit form
    address_input.send_keys(address)
    postcode_input.send_keys(postcode)
    postcode_input.send_keys(Keys.RETURN)
    
    # Check Available - Inner iframe
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"CreativeLiftFrame")))
    print(WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'body'))).get_attribute("id"))
    

提交回复
热议问题