我正在尝试切换到上一帧。
在我的代码中
但是,我需要切换到 BRVT1Frame 之前的帧。
这是我的代码:
BRT1Frame=driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
buttons=driver.find_elements_by_css_selector("button")
for button in buttons:
if button.text.strip()=="Create Community":
button.click()
#A new pop up window causes me to switch windows
for handle in driver.window_handles:
BRT=driver.switch_to_window(handle)
print(BRT)
#then I switch frames
driver.switch_to_frame(driver.find_element_by_class_name("FormDialogIFrame"))
driver.find_element_by_id("CommunityFormCommunityNameTextBox").send_keys("1st MEB STAFFEX")
save=driver.find_element_by_id("CommunityFormSaveButton").click()
#that popup closes now I have to switch to another frame
我试图切换到代码的框架:
<iframe role="presentation"
class="x-component x-window-item x-component-default"
src="/brvt?lang=en_US&owf=true&themeName=a_default&
themeContrast=standard&themeFontSize=12"
name="{"id":"778a1259-bc80-602e-c0ad-16a3f9220516","containerVersion":"7-GA","webContextPath":"/owf","preferenceLocation":"https://www.url,com;,"relayUrl":"https://url.com/55js/even/rpc_relay.uncompressed.html","lang":"en_US","currentTheme":{"themeName":"a_default","themeContrast":"standard","themeFontSize":12},"55f":true,"layout":"desktop","url":"/brvt","guid":"260f0022-66de-a78b-3ce8-8de63a3bdbec","version":1,"locked":false}"
id="{"id":"778a1259-bc80-602e-c0ad-16a3f9220516"}"
frameborder="0"></iframe>
我试过这样做:
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
这很有效,但当我尝试点击框架内的下拉菜单时:
driver.find_element_by_css_selector("#OYk3vd6NKj1jbrnew > td.sub_item_text").click()
我也尝试过:
driver.switch_to_frame(driver.find_element_by_id("{"id":"778a1259-bc80-602e-c0ad-16a3f9220516"}")
我收到一条错误消息,指出无法找到该元素。 建议?
答案 0 :(得分:2)
如果您只想找到指定的确切帧,请尝试:
func serveResource(w http.ResponseWriter, req *http.Request) {
path := "../../public" + req.URL.Path
http.ServeFile(w, req, path)
}
甚至更具体:
required_frame = driver.find_element_by_xpath('//iframe[@role="presentation"]')
driver.switch_to_frame(required_frame)
这个建议有用吗?