From 71e6c1e2afe451b670c56cb37f7de98db896e8fc Mon Sep 17 00:00:00 2001 From: Pallavi Date: Thu, 26 Sep 2024 23:44:14 +0530 Subject: [PATCH] added code for frames for csharp (#1961)[deploy site] added code for frames for csharp Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com> --- .../SeleniumDocs/Interactions/FramesTest.cs | 69 ++++++++++++++++++- .../webdriver/interactions/frames.en.md | 47 ++++--------- .../webdriver/interactions/frames.ja.md | 47 ++++--------- .../webdriver/interactions/frames.pt-br.md | 40 ++++------- .../webdriver/interactions/frames.zh-cn.md | 32 +++------ 5 files changed, 111 insertions(+), 124 deletions(-) diff --git a/examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs b/examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs index f2ab19af117d..85f7573c883f 100644 --- a/examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs +++ b/examples/dotnet/SeleniumDocs/Interactions/FramesTest.cs @@ -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("admin@selenium.dev"); + 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("admin@selenium.dev"); + 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(); + } } } \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.en.md b/website_and_docs/content/documentation/webdriver/interactions/frames.en.md index 6900c6b2de14..4c02033c24c7 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.en.md @@ -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') @@ -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' @@ -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); @@ -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 diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md b/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md index 0c02e8d41b90..97ae27619657 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.ja.md @@ -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') @@ -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'); @@ -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] @@ -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 diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md b/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md index 6effc3ad22fa..0fd61db35931 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md @@ -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') @@ -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' @@ -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] @@ -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 diff --git a/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md b/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md index 4f6696307018..af55faf58226 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md @@ -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 @@ -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 @@ -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 @@ -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" >}} # 回到顶层