2012-02-03 21 views
9

का उपयोग करके नेस्टेड आईफ्रेम ढूंढना मैं एक विरासत अनुप्रयोग के लिए परीक्षण लिख रहा हूं जिसमें मुख्य दस्तावेज़ में आईफ्रेम है, और उसके बाद एक और आईफ्रेम है। तो पदानुक्रम है:सेलेनियम 2

Html Div (id = tileSpace) 
    iFrame (id = ContentContainer) 
    iFrame (id = Content) 
     Elements 

यह मेरा कोड (मैं सी # का उपयोग कर रहा)

RemoteWebDriver driver = new InternetExplorerDriver(); 
var tileSpace = driver.FindElement(By.Id("tileSpace")); 
var firstIFrame = tileSpace.FindElement(By.Id("ContentContainer")); 
var contentIFrame = firstIFrame.FindElement(By.Id("Content")); 

समस्या है, मैं 2 स्तर iFrame यानी contentIFrame

कोई भी विचार तक नहीं पहुंच पा रहा है ?

उत्तर

19

मैं वर्तमान में इसी तरह की वेबसाइट पर परीक्षण कर रहा हूं। (मुख्य दस्तावेज़ के अंदर नेस्टेड iframes का)

<div> 
    <iframe> 
     <iframe><iframe/> 
    <iframe/> 
</div> 

यह है कि आप frame switching method एपीआई में प्रदान की जाती का उपयोग नहीं कर रहे हैं। यह समस्या हो सकती है।

यह वही है जो मैं कर रहा हूं, यह मेरे लिए ठीक काम करता है।

//make sure it is in the main document right now 
driver.SwitchTo().DefaultContent(); 

//find the outer frame, and use switch to frame method 
IWebElement containerFrame = driver.FindElement(By.Id("ContentContainer")); 
driver.SwitchTo().Frame(containerFrame); 

//you are now in iframe "ContentContainer", then find the nested iframe inside 
IWebElement contentFrame = driver.FindElement(By.Id("Content")); 
driver.SwitchTo().Frame(contentFrame); 

//you are now in iframe "Content", then find the elements you want in the nested frame now 
IWebElement foo = driver.FindElement(By.Id("foo")); 
+0

धन्यवाद! बहुत अच्छी तरह से काम किया। – user356247

0

कोड के नीचे का प्रयास करें:

//Switch to required frame 
    driver.SwitchTo().Frame("ContentContainer").SwitchTo().Frame("Content"); 

    //find and do the action on required elements 

    //Then come out of the iFrame 
    driver.SwitchTo().DefaultContent(); 
संबंधित मुद्दे