Select iframe using Python + Selenium

后端 未结 6 752
Happy的楠姐
Happy的楠姐 2020-11-22 12:13

So, I was absolutely baffled as to how to do this in Selenium, and couldn\'t find the answer anywhere, so I\'m sharing my experience.

I was trying to select an ifram

6条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 12:43

    Selenium's selectFrame command accepts all the standard locators like css=, but it also has a an extra set of locators that work specifically with FRAME and IFRAME elements.

    As the doc says:

    selectFrame ( locator ) Selects a frame within the current window. (You may invoke this command multiple times to select nested frames.) To select the parent frame, use "relative=parent" as a locator; to select the top frame, use "relative=top". You can also select a frame by its 0-based index number; select the first frame with "index=0", or the third frame with "index=2".

    You may also use a DOM expression to identify the frame you want directly, like this: dom=frames["main"].frames["subframe"]

    Arguments: locator - an element locator identifying a frame or iframe

    In general, you'll have better luck using the specialized locators, especially if you establish the right context first (e.g., select_frame("relative=top"); select_frame("id=upload_file_frame");).

提交回复
热议问题