SeleniumBasic icon indicating copy to clipboard operation
SeleniumBasic copied to clipboard

Unable to click button inside frame using selenium vba

Open naveenorangeboy opened this issue 6 years ago • 6 comments

I am beginner to vba selenium. i want to click a button which is inside a frame. i tried with below codes it didn't work. Can anyone help me? Thanks VBA Code: ch.SwitchToFrame (1) ch.FindElementByXPath("//*[@id='ctl00_m_g_4407ef25_fbd3_4301_922c_f996c0f26235_FormControl0_V1_I1_B3']") HTML Code: <input style="text-align:center" onclick="return (Button.OnClick(this, event));" onfocus="return (Button.OnFocus(this, event));" id="ctl00_m_g_4407ef25_fbd3_4301_922c_f996c0f26235_FormControl0_V1_I1_B3" scriptclass="Button" class="i_lgkamPX909UfcKnV_3 a4_lgkamPX909UfcKnV_3 a2_lgkamPX909UfcKnV_3" wrapped="true" direction="ltr" viewdatanode="4" formid="ctl00_m_g_4407ef25_fbd3_4301_922c_f996c0f26235_FormControl0" originalid="V1_I1_B3" tabindex="0" title="" buttonid="CTRL2" value="Vendor" type="button">

naveenorangeboy avatar Mar 01 '19 04:03 naveenorangeboy

Hello. Remember that switchtoframe uses a zero-based index. Try "switchtoFrame(0)".

Juampa2 avatar Mar 01 '19 11:03 Juampa2

@Juampa2 Thanks for your response. I tried that too. I get run-time error 7 NoSuchElementError Element not found for XPath=//*[

naveenorangeboy avatar Mar 01 '19 12:03 naveenorangeboy

Does it got anything to do with browser version and driver version? Mine is chrome Version 63.0.3239.108

naveenorangeboy avatar Mar 01 '19 13:03 naveenorangeboy

once the driver has started, pause the code just before ch.SwitchToFrame (1) and try to modify the frame id manually : in the developper tool of your browser (if you're using Chrome for example : F12). Find the in which your id='ctl00_m_g_4407ef25_fbd3_4301_922c_f996c0f26235_FormControl0_V1_I1_B3' is and add something like . Then, try : ch.SwitchToFrame("mytest") just to make sure the driver is switching on the correct frame. And then, once you're sure that the correct frame has been switched on, try ch.FindElementById("ctl00_m_g_4407ef25_fbd3_4301_922c_f996c0f26235_FormControl0_V1_I1_B3") instead of XPath.

Larbalette avatar Mar 24 '19 10:03 Larbalette

if it works, then it means probably that you have many frames and switching to frame as you do does not ensure you that you've switched on the correct frame.

Larbalette avatar Mar 24 '19 10:03 Larbalette

As a workaround, I try to open the frame separately, then access its elements.

stylishbharath avatar Nov 14 '20 23:11 stylishbharath