首页 > 解决方案 > VBA-想要单击具有多个框架的元素

问题描述

有了上一个问题的答案,我向前迈进了一步,但仍然停留在我想单击该元素的地方,但它似乎有 2 帧,这就是我运行代码时给出的错误该元素未找到的原因,请检查附件和下面代码和建议。

Sub activeBexIE_Final()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

'On Error Resume Next
Dim Perm_bot As New Selenium.IEDriver         
  
Perm_bot.Get "official link"

Perm_bot.Wait 2000

Perm_bot.FindElementById("logonuidfield").SendKeys "XYZ"
Perm_bot.SendKeys Perm_bot.Keys.Tab
Perm_bot.SendKeys "PQR"
Perm_bot.SendKeys Perm_bot.Keys.Enter
Perm_bot.Wait 40000

Perm_bot.switchToFrame 
Perm_bot.FindElementById("iframe_Roundtrip_9223372036563636042")
Perm_bot.FindElementById("BUTTON_OPEN_SAVE_btn1_acButton").SendKeys 
Perm_bot.Keys.Enter
Perm_bot.Wait 30000' *till here I am sucessful- Opening Url-login-click on 
"Open" option*

*'from here I am unable to move further, pls check attachment"select 
layout" like how I wanted to select and also check the attachment "frame" 
and "element" which is having the HTML details, not sure if this particular 
element has 2 element, if yes then how I should write the script and after 
this I wanted to do  tab 7 times and then enter, kindly help for further 
script, thanks in advance

'Perm_bot.switchToFrame Perm_bot.FindElementById("urPopupOuter0")

Perm_bot.switchToFrame Perm_bot.FindElementById("urPopupInner0")

Perm_bot.FindElementById("LOAD_state_tigen4_tlv1_list_unid6_tv").Click

SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{TAB}"
SendKeys "{ENTER}"
    
Perm_bot.Wait 10000
  
Application.DisplayAlerts = True
Application.ScreenUpdating = True
 
    'perm_dot.Quit
'Set perm_dot = Nothing
    
End Sub

选择布局 框架元素

标签: vbaseleniuminternet-explorerweb-scrapingiframe

解决方案


I believe your concern is your iframes are having similar attributes and you have to switch to each one of it before tabing 7 times.

Approach would be Just like getting all windows handles and then loop you can use common xpath for iframe for e.g

   findelements(By.Xpath("//iframes))

this will return iframe elements and then you can use loop and traverse and use

SwitchToFrame().


推荐阅读