Skip to content

added code for frames for csharp #1961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading