Jump to content

Not able to get the elements in iframe using _WD_FrameEnter


Recommended Posts

 

Hi All,

I am training to access the button control in webpage which has iframe, I used _WD_FrameEnter method to switch the current content to first frame and tried to get the controls but no luck, can anyone help me? may be I am doing something wrong here since first time I am dealing with iframes.

below is the code I tried 

    _WD_Navigate($Session, 'https://ecomm.one-line.com/one-ecom/manage-shipment/cargo-tracking')
    _WD_LoadWait($Session, Default, 10 * 1000)

    ConsoleWrite("Frames Count=" & _WD_GetFrameCount($Session) & @CRLF)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($Session) & @CRLF)

    $sElement = _WD_FindElement($Session, $_WD_LOCATOR_ByXPath, "//iframe[(@id='IframeCurrentEcom')]")
    _WD_FrameEnter($Session, $sElement)

 
     $sButton = _WD_FindElement($Session, $_WD_LOCATOR_ByXPath, "//button[(@id='btnSearch')]")
    MsgBox(0,'$sButton',$sButton)
    _WD_ElementAction($Session, $sButton, 'click')
    _WD_LoadWait($Session, 2000)

Link to post
Share on other sites

1) You should get in the habit of reviewing the Scite output panel to diagnose why your script isn't behaving as expected. When I did this, I saw that the Frame wasn't being found.

2) You need to wait until the page is fully loaded. I changed your code slightly and it worked correctly for me --

_WD_Navigate($Session, 'https://ecomm.one-line.com/one-ecom/manage-shipment/cargo-tracking')
    _WD_LoadWait($Session, Default, 10 * 1000)
    $sXpath = "//iframe[(@id='IframeCurrentEcom')]"
    _WD_WaitElement($Session, $_WD_LOCATOR_ByXPath, $sXpath)
    ConsoleWrite("Frames Count=" & _WD_GetFrameCount($Session) & @CRLF)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($Session) & @CRLF)
    $sElement = _WD_FindElement($Session, $_WD_LOCATOR_ByXPath, $sXpath)
    _WD_FrameEnter($Session, $sElement)

 
     $sButton = _WD_FindElement($Session, $_WD_LOCATOR_ByXPath, "//button[(@id='btnSearch')]")
    MsgBox(0,'$sButton',$sButton)
    _WD_ElementAction($Session, $sButton, 'click')
    _WD_LoadWait($Session, 2000)

 

Link to post
Share on other sites

Hi @Danp2

Thank you so much for your solution.

you are correct I didn't check whether the iFram is getting captured or not, also honestly I did not know this command _WD_WaitElement, however I am very beginner for AutoIt scripting and your guidance are very helpful. 

after checking with _WD_WaitElement I am able to find the controls. thanks 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...