When an element is in a ifarm or farm, it needs to be entered into the form before the element can be positioned for manipulation. Position the element directly. will prompt the element to not be found.
<!DOCTYPE HTML><HTML><Head></Head><Body><iframeID= ' If 'src= "Https://www.baidu.com"width= "$"Height= ' + '></iframe></Body></HTML>
Save the above HTML code in a text editor, not in a notebook in Windows. The file name is random, suffix name. html or HTM
Use Switch_to.frame () to switch the form, by default using ID or name positioning, you can directly pass the corresponding value. If you don't have an ID or name attribute, you can only navigate to it by other means and then pass it in.
from Import = webdriver. Chrome () Dr.maximize_window () dr.get ('file:///C:/Users/ms/Desktop/dr.html') Dr.switch_to.frame ('if'= dr.find_element_by_id ('kw ')# Locate search Input box st.send_keys ('selenium')
You can try to remove the switch form code, it will prompt the element can not be found.
With Driver.switch_to.parent_frame (), if it is a multi-layer frame, you can jump back from the child frame to the parent frame
Use Driver.switch_to.default_content () to switch back to the main document, that is, jump out of all frame
Python3+selenium Getting Started 10-form switching