【问题标题】:Can't find element in webpage using selenium C#?使用 selenium C# 在网页中找不到元素?
【发布时间】:2016-02-23 10:38:07
【问题描述】:

在页面中找不到任何元素有 2 个嵌套在 selenium 中的 iframe?

第一次启动时,我在浏览器中找到了所有元素,但何时转到 iframe[0] 我在浏览器中找不到任何元素。

我的代码如下:

var iframes = browser.FindElementsByXPathName("//iframe[contains(@id,'container_page')]");
while (browser.FindElementsByXPathName("//span[contains(@class, 'button_Love')]").Count == 0 && iframes.Count == 0)
    Thread.Sleep(1000);
if (iframes.Count > 0)
{
    browser.GoToFrame(iframes[0]);
    Thread.Sleep(2000);
}

【问题讨论】:

    标签: c# selenium iframe


    【解决方案1】:

    试试下面的代码。

       var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("you URL");
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
            //check if there is any iframe then get that frame and switch on frame using folloiwng code.
            var frame = wait.Until(ExpectedConditions.ElementExists(By.Id("frame_id")));
            driver.SwitchTo().Frame(frame);
            var elementbutton_Love = driver.FindElements(By.ClassName("button_Love"));
    
            //after doing all work you can go to default content using  following code
            driver.SwitchTo().DefaultContent();
    

    如果有任何问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-04
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2020-03-24
      相关资源
      最近更新 更多