Skip to content

Commit

Permalink
added code for frames for csharp (#1961)[deploy site]
Browse files Browse the repository at this point in the history
added code for frames for csharp

Co-authored-by: Sri Harsha <[email protected]>
  • Loading branch information
pallavigitwork and harsha509 authored Sep 26, 2024
1 parent 914d0c5 commit 71e6c1e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 124 deletions.
69 changes: 67 additions & 2 deletions examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,74 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Collections.Generic;

namespace SeleniumDocs.Interactions
{
[TestClass]
public class FramesTest : BaseTest
[TestClass]
public class FramesTest
{
[TestMethod]
public void TestFrames()
{
WebDriver driver = new ChromeDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);

// Navigate to Url
driver.Url= "https://www.selenium.dev/selenium/web/iframes.html";
//switch To IFrame using Web Element
IWebElement iframe = driver.FindElement(By.Id("iframe1"));
//Switch to the frame
driver.SwitchTo().Frame(iframe);
Assert.AreEqual(true, driver.PageSource.Contains("We Leave From Here"));
//Now we can type text into email field
IWebElement emailE = driver.FindElement(By.Id("email"));
emailE.SendKeys("[email protected]");
emailE.Clear();
driver.SwitchTo().DefaultContent();


//switch To IFrame using name or id
driver.FindElement(By.Name("iframe1-name"));
//Switch to the frame
driver.SwitchTo().Frame(iframe);
Assert.AreEqual(true, driver.PageSource.Contains("We Leave From Here"));
IWebElement email = driver.FindElement(By.Id("email"));
//Now we can type text into email field
email.SendKeys("[email protected]");
email.Clear();
driver.SwitchTo().DefaultContent();


//switch To IFrame using index
driver.SwitchTo().Frame(0);
Assert.AreEqual(true, driver.PageSource.Contains("We Leave From Here"));

//leave frame
driver.SwitchTo().DefaultContent();
Assert.AreEqual(true, driver.PageSource.Contains("This page has iframes"));

//quit the browser
driver.Quit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,9 @@ driver.switch_to.frame(iframe)
# Now click on button
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
//Store the web element
IWebElement iframe = driver.FindElement(By.CssSelector("#modal>iframe"));

//Switch to the frame
driver.SwitchTo().Frame(iframe);

//Now we can click the button
driver.FindElement(By.TagName("button")).Click();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Store iframe web element
iframe = driver.find_element(:css,'#modal > iframe')
Expand Down Expand Up @@ -144,16 +137,9 @@ driver.switch_to.frame('buttonframe')
# Now, Click on the button
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
//Using the ID
driver.SwitchTo().Frame("buttonframe");

//Or using the name instead
driver.SwitchTo().Frame("myframe");

//Now we can click the button
driver.FindElement(By.TagName("button")).Click();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch by ID
driver.switch_to.frame 'buttonframe'
Expand Down Expand Up @@ -199,17 +185,9 @@ queried using _window.frames_ in JavaScript.
# Switch to the second frame
driver.switch_to.frame(1)
{{< /tab >}}
{{< tab header="CSharp" >}}
// Switches to the second frame
driver.SwitchTo().Frame(1);
{{< /tab >}}
{{< tab header="Python" >}}
# switching to second iframe based on index
iframe = driver.find_elements(By.TAG_NAME,'iframe')[1]

# switch to selected iframe
driver.switch_to.frame(iframe)
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Switches to the second frame
await driver.switchTo().frame(1);
Expand All @@ -236,10 +214,9 @@ like so:
# switch back to default content
driver.switch_to.default_content()
{{< /tab >}}
{{< tab header="CSharp" >}}
// Return to the top level
driver.SwitchTo().DefaultContent();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Return to the top level
driver.switch_to.default_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,9 @@ driver.switch_to.frame(iframe)
# Now click on button
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
//Store the web element
IWebElement iframe = driver.FindElement(By.CssSelector("#modal>iframe"));

//Switch to the frame
driver.SwitchTo().Frame(iframe);

//Now we can click the button
driver.FindElement(By.TagName("button")).Click();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Store iframe web element
iframe = driver.find_element(:css,'#modal > iframe')
Expand Down Expand Up @@ -132,23 +125,9 @@ driver.switch_to.frame('buttonframe')
# Now, Click on the button
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
//Using the ID
driver.SwitchTo().Frame("buttonframe");

//Or using the name instead
driver.SwitchTo().Frame("myframe");

//Now we can click the button
driver.FindElement(By.TagName("button")).Click();
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch by ID
driver.switch_to.frame 'buttonframe'

# Now, Click on the button
driver.find_element(:tag_name,'button').click
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
// Using the ID
await driver.switchTo().frame('buttonframe');
Expand Down Expand Up @@ -183,10 +162,9 @@ JavaScriptの _window.frames_ を使用して照会できるように、Frameの
# Switch to the second frame
driver.switch_to.frame(1)
{{< /tab >}}
{{< tab header="CSharp" >}}
// Switches to the second frame
driver.SwitchTo().Frame(1);
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# switching to second iframe based on index
iframe = driver.find_elements(By.TAG_NAME,'iframe')[1]
Expand Down Expand Up @@ -217,10 +195,9 @@ iFrameまたはFrameセットを終了するには、次のようにデフォル
# switch back to default content
driver.switch_to.default_content()
{{< /tab >}}
{{< tab header="CSharp" >}}
// Return to the top level
driver.SwitchTo().DefaultContent();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Return to the top level
driver.switch_to.default_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,9 @@ driver.switch_to.frame(iframe)
# Now click on button
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
//Store the web element
IWebElement iframe = driver.FindElement(By.CssSelector("#modal>iframe"));

//Switch to the frame
driver.SwitchTo().Frame(iframe);

//Now we can click the button
driver.FindElement(By.TagName("button")).Click();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Store iframe web element
iframe = driver.find_element(:css,'#modal > iframe')
Expand Down Expand Up @@ -140,16 +133,9 @@ driver.switch_to.frame('buttonframe')
# Now, Click on the button
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
//Using the ID
driver.SwitchTo().Frame("buttonframe");

//Or using the name instead
driver.SwitchTo().Frame("myframe");

//Now we can click the button
driver.FindElement(By.TagName("button")).Click();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch by ID
driver.switch_to.frame 'buttonframe'
Expand Down Expand Up @@ -192,10 +178,9 @@ consultado usando _window.frames_ em JavaScript.
# Switch to the second frame
driver.switch_to.frame(1)
{{< /tab >}}
{{< tab header="CSharp" >}}
// Switches to the second frame
driver.SwitchTo().Frame(1);
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# switching to second iframe based on index
iframe = driver.find_elements(By.TAG_NAME,'iframe')[1]
Expand Down Expand Up @@ -227,10 +212,9 @@ como a seguir:
# switch back to default content
driver.switch_to.default_content()
{{< /tab >}}
{{< tab header="CSharp" >}}
// Return to the top level
driver.SwitchTo().DefaultContent();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Return to the top level
driver.switch_to.default_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ driver.switch_to.frame(iframe)
# 单击按钮
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
// 存储网页元素
IWebElement iframe = driver.FindElement(By.CssSelector("#modal>iframe"));

// 切换到 frame
driver.SwitchTo().Frame(iframe);

// 现在可以点击按钮
driver.FindElement(By.TagName("button")).Click();
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L38-L46" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Store iframe web element
Expand Down Expand Up @@ -133,15 +126,8 @@ driver.switch_to.frame('buttonframe')
# 单击按钮
driver.find_element(By.TAG_NAME, 'button').click()
{{< /tab >}}
{{< tab header="CSharp" >}}
// 使用 ID
driver.SwitchTo().Frame("buttonframe");

// 或者使用 name 代替
driver.SwitchTo().Frame("myframe");

// 现在可以点击按钮
driver.FindElement(By.TagName("button")).Click();
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L50-L58" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# Switch by ID
Expand Down Expand Up @@ -186,9 +172,8 @@ _window.frames_ 进行查询.
# 切换到第 2 个框架
driver.switch_to.frame(1)
{{< /tab >}}
{{< tab header="CSharp" >}}
// 切换到第 2 个框架
driver.SwitchTo().Frame(1);
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L62-L63" >}}
{{< /tab >}}
{{< tab header="Python" >}}
# 基于索引切换到第 2 个 iframe
Expand Down Expand Up @@ -220,9 +205,8 @@ driver.switchTo().frame(1)
# 切回到默认内容
driver.switch_to.default_content()
{{< /tab >}}
{{< tab header="CSharp" >}}
// 回到顶层
driver.SwitchTo().DefaultContent();
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs#L66-L67" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
# 回到顶层
Expand Down

0 comments on commit 71e6c1e

Please sign in to comment.