Need Help in getting XPath expression for span inside an Iframe popup

前端 未结 5 464
清歌不尽
清歌不尽 2021-01-02 23:30

Need to get an xpath expression for the span inside the iframe. Need Help in getting XPath expression for span inside an Iframe popup.

i can get the iframe but getti

相关标签:
5条回答
  • 2021-01-02 23:46

    You need to set the scope of the xpath to the iframe's contentDocument property:

    var iframe = document.getElementsByTagName("iframe")[0];
    var theFirstSpan = document.evaluate('//span', iframe.contentDocument,
             null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
    
    0 讨论(0)
  • 2021-01-02 23:48

    Use:

    //iframe//span
    

    This selects every span element that is a descendent of any iframe element in the XML document.

    0 讨论(0)
  • 2021-01-03 00:00
    //span [ancestor::iframe]
    

    This will select all span elements which at some point have an ancestor iframe element.

    0 讨论(0)
  • 2021-01-03 00:10

    Elements in iframe are in fact in another page. so you should first find address of that page which is value of src value of iframe and load it and then access the element in that page.

    0 讨论(0)
  • 2021-01-03 00:10

    We can't access elements within an iframe directly. We need to switch to iframe first.

    I am using PHP Facebook webdriver and this is perfectly working for me:

    $driver->get("http://www.example.com"); // containing an iframe
    $iFrame = $driver->findElement(
                WebDriverBy::xpath('//iframe[@name="iFrameName"]') //name or id or whatever by which we can access.
            );
    $driver->switchTo()->frame($iFrame);
    

    Now, we can access that span as:

    $spanButton = $driver->findElement(
                WebDriverBy::xpath('//span') 
            );
    
    0 讨论(0)
提交回复
热议问题