Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

c# - time out when switching to a specific iframe

I am having trouble switching to a specific iframe. time out occurs when trying to switch to the first iframe in the last step in the code below (//set macro).

I tried so many solutions such as increasing the time out from 60 to 120 sec, or adding:

chromeOptions.PageLoadStrategy = PageLoadStrategy.Normal; 
chromeOptions.AddArgument("no-sandbox");

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Threading;
using OpenQA.Selenium.Interactions;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var chromeOptions = new ChromeOptions();
            chromeOptions.PageLoadStrategy = PageLoadStrategy.Normal;
            chromeOptions.AddArgument("no-sandbox");
            ChromeDriver ffDriver = new ChromeDriver("C:/selenium/webdriver", chromeOptions, TimeSpan.FromSeconds(120));
            ffDriver.Navigate().GoToUrl(@"https://qatraining5.intellect.com/Intellect/");
            ffDriver.Manage().Timeouts().PageLoad.Add(System.TimeSpan.FromSeconds(10));
            ffDriver.Manage().Window.Maximize();

            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("/html/body/form/iframe")));

            //enter user name
            ffDriver.FindElement(By.XPath("//form/table/tbody/tr[2]/td/input")).Click();
            ffDriver.FindElement(By.CssSelector("#Username")).SendKeys("Designer");

            //login
            ffDriver.FindElement(By.XPath("//table/tbody/tr/td/table/tbody/tr[4]/td/table/tbody/tr/td/div/form/table/tbody/tr[6]/td/input[@type='submit']")).Click();

            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("/html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/div/iframe")));

            ffDriver.FindElement(By.XPath("//form/div[2]/table/tbody/tr[3]/td/div/table[6]/tbody/tr/td[1]/div/div/div/h1")).Click();

            //template tab
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.FindElement(By.CssSelector("#TabHeader_1000000009")).Click();

            //design tab
            ffDriver.FindElement(By.XPath("//td//td[. = 'DESIGN']")).Click();
            ffDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);

            //insert category
            ffDriver.FindElement(By.CssSelector("#Button_Text_INSERTCATEGORY_Label")).Click();

            //rename the category
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("/html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/div/iframe")));
            ffDriver.FindElement(By.XPath("/html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[10]/td[2]/table/tbody/tr[1]/td[2]/div/table/tbody/tr[1]/td[2]/input")).SendKeys("Macro Testing" + Keys.Return);

            //open the category
            ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[10]/td[2]/table/tbody/tr[1]/td[2]/div/table/tbody/tr[1]/td[2]/span")).Click();

            //insert Template
            ffDriver.SwitchTo().DefaultContent();
            Thread.Sleep(9000);
            ffDriver.FindElement(By.XPath("/html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[1]/td[1]/div[2]/div[1]/table/tbody/tr/td[2]/table/tbody/tr/td[2]/div/span")).Click();

            //rename the template
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("/html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/div/iframe")));
            ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[2]/div/table/tbody/tr[1]/td[2]/input")).SendKeys("Group 1 Macro" + Keys.Return);

            //open the template
            ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[2]/div/table/tbody/tr[1]/td[2]/span")).Click();

            //open the toolbox
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/div/iframe")));
            ffDriver.FindElement(By.XPath("/html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/span[1]")).Click();

            //expand the first controls set
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/table[1]/tbody/tr[3]/td[1]/table/tbody/tr[2]/td/div/iframe")));
            ffDriver.FindElement(By.XPath("//html/body/table/tbody/tr[1]/td")).Click();

            //insert a DD
            ffDriver.FindElement(By.XPath("//html/body/table/tbody/tr[2]/td/table/tbody/tr[15]")).Click();

            //rename the DD
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("/html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/div/iframe")));
            ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]/div/input")).SendKeys("Type" + Keys.Return);

            //rigth click the DD
            Actions actionOne = new Actions(ffDriver);
            actionOne.ContextClick(ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]/div"))).Perform();

            //click properties
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.FindElement(By.XPath("/html/body/div[15]/ul/li[22]/span")).Click();

            //select the 1st option and delete it
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/div[16]/iframe[2]")));
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[1]/td[2]/select/option[1]")).Click();
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[3]/td[1]/img[2]")).Click();

            //select the 2nd option and delete it
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[1]/td[2]/select/option[1]")).Click();
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[3]/td[1]/img[2]")).Click();

            //insert option A
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[3]/td[2]/input")).SendKeys("A");
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[3]/td[1]/img[1]")).Click();

            //insert option B
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[3]/td[2]/input")).SendKeys("B");
            ffDriver.FindElement(By.XPath("//html/body/div/form/table[1]/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table[4]/tbody/tr[3]/td[1]/img[1]")).Click();

            //ok
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.FindElement(By.XPath("//html/body/div[16]/table[2]/tbody/tr/td[2]/table/tbody/tr/td[1]/table/tbody/tr/td/span")).Click();

            //insert txt
            Thread.Sleep(8000);
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/table[1]/tbody/tr[3]/td[1]/table/tbody/tr[2]/td/div/iframe")));
            Thread.Sleep(2000);
            ffDriver.FindElement(By.XPath("//html/body/table/tbody/tr[2]/td/table/tbody/tr[1]")).Click();

            //rename txt
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("/html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/div/iframe")));
            ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[4]/td[2]/div/input")).SendKeys("Linked" + Keys.Return);

            //right click txt
            Actions actionTwo = new Actions(ffDriver);
            actionTwo.ContextClick(ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr[4]/td[2]/div/label"))).Perform();

            //click properties 
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.FindElement(By.XPath("/html/body/div[15]/ul/li[22]/span")).Click();

            //conditions tab
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/div[16]/iframe[2]")));
            ffDriver.FindElement(By.XPath("//html/body/div/form/div/table/tbody/tr/td[2]")).Click();

            //no edit radio button
            ffDriver.FindElement(By.XPath("/html/body/div/form/table[1]/tbody/tr[2]/td/table[2]/tbody/tr/td[2]/table[1]/tbody/tr/td/table/tbody/tr/td[2]/input")).Click();

            //ok
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.FindElement(By.XPath("//html/body/div[16]/table[2]/tbody/tr/td[2]/table/tbody/tr/td[1]/table/tbody/tr/td/span")).Click();
            Thread.Sleep(9000);

            //insert button
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/table[1]/tbody/tr[3]/td[1]/table/tbody/tr[2]/td/div/iframe")));
            Thread.Sleep(1000);
            ffDriver.FindElement(By.XPath("//html/body/table/tbody/tr[2]/td/table/tbody/tr[25]/td[3]")).Click();

            //rename the button
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/table[1]/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/div/iframe")));
            ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/input[2]")).SendKeys("Macros" + Keys.Return);

            //right click
            Actions actionThree = new Actions(ffDriver);
            actionThree.ContextClick(ffDriver.FindElement(By.XPath("//html/body/form/table[1]/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div"))).Perform();

            //properties
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.FindElement(By.XPath("/html/body/div[15]/ul/li[22]/span")).Click();

            //macro editor
            ffDriver.SwitchTo().DefaultContent();
            ffDriver.SwitchTo().Frame(ffDriver.FindElement(By.XPath("//html/body/div[16]/iframe[2]")));
            Thread.Sleep(2000);
            ffDriver.FindElement(By.XPath("//html/body/div/form/table/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/input")).Click();

            //set macro
            ffDriver.SwitchTo().DefaultC

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...