selenium: how to know if element in located in iframe

  Kiến thức lập trình

I’m having trouble locating the following element circled in red (please see image below):

https://www.reddit.com/r/Watchexchange/submit/?type=IMAGE

and believe it may be in a frame. The element:

<button rpl="" class="upload-media action
button-small px-[var(--rem6)]
button-secondary


icon
items-center justify-center
button inline-flex " id="device-upload-button" type="button"> <!--?lit$869276182$--><!----><span class="flex items-center justify-center"> <!--?lit$869276182$--><span class="flex"><!--?lit$869276182$--><svg rpl="" fill="currentColor" height="16" icon-name="upload-outline" viewBox="0 0 20 20" width="16" xmlns="http://www.w3.org/2000/svg"> <!--?lit$869276182$--><!--?lit$869276182$--><path d="m10.513 5.63 3.929 3.928-.884.884-2.933-2.933V19h-1.25V7.51l-2.933 2.932-.884-.884L9.67 5.446l.589-.029.254.212Zm5.859-1.482A6.876 6.876 0 0 0 10 0a6.876 6.876 0 0 0-6.372 4.148A4.639 4.639 0 0 0 0 8.625a4.716 4.716 0 0 0 4.792 4.625V12A3.465 3.465 0 0 1 1.25 8.625 3.412 3.412 0 0 1 4.189 5.31l.364-.06.123-.35A5.607 5.607 0 0 1 10 1.25a5.607 5.607 0 0 1 5.324 3.65l.123.348.364.06a3.412 3.412 0 0 1 2.939 3.317A3.465 3.465 0 0 1 15.208 12v1.25A4.716 4.716 0 0 0 20 8.625a4.639 4.639 0 0 0-3.628-4.477Z"></path><!--?--> </svg></span> <!--?lit$869276182$--> </span> <!--?lit$869276182$--><!--?--><!----><!----><faceplate-screen-reader-content><!--?lit$869276182$-->Upload files</faceplate-screen-reader-content><!----> </button>

I tried the following first assuming it wasn’t in a frame:

wait.until(EC.presence_of_element_located((By.ID, 'device-upload-button')))
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="device-upload-button"]')))
wait.until(EC.presence_of_element_located((By.XPATH, '//button[contains(@class,'flex items-center justify-center')]')))

but it didn’t work, which leads me to think its in a frame that I need to switch to first. Here’s the surrounding html:

surrounding html

New contributor

rickw is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT