Selenium WebDriver.FindElements(By.CssSelector(" *"))找不到元素,C#

时间:2016-05-15 10:21:46

标签: c# selenium webdriver

我正在寻找ID" lastdays_day"为:

WebDriver.FindElements(By.CssSelector("*")) 

但elements.Count为0。

偶:

Driver.SwitchTo().DefaultContent

无法列出此元素

我在页面加载后尝试过Thread.Sleep(5000)但是没有用。 我试过了

Driver.SwitchTo().Frame(0)

Notice on line 328 in file modules/swipe/swipe.php
[8] Undefined property: Swipe::$_postErrors




   public function getContent() {
        $this->_html = '<img src="'.$this->_p otocol.$this->context->shop->domain.$this->_path.'logo-big.png" style="margin-bottom:20px" />';
        if (Tools::isSubmit('btnSubmit')) {
            $this->_postValidation();
            if (!count($this->_postErrors))    **((Line 328))**
                $this->_postProcess();
            else
                foreach ($this->_postErrors as $err)
                    $this->_html .= '<div class="alert error">' . $err . '</div>';
        }
        else
            $this->_html .= '<br />';

        $this->_displayTop();
        $this->_displayForm();

        return $this->_html;
    }
}

但不起作用。

有什么想法吗?

structure of the page

1 个答案:

答案 0 :(得分:1)

Driver.SwitchTo().DefaultContent;将切换 out

由于html中的索引从1开始,因此

Driver.SwitchTo().Frame(0);无法正常工作。

Driver.SwitchTo()可以接收ID / name作为参数,因此switch命令应该看起来像

Driver.SwitchTo().Frame("ombframe"); // switch to first frame
Driver.SwitchTo().Frame("MainFrame"); // switch to second frame

作为旁注,元素的ID为lastdays_days,其中包含&#39;而不是lastdays_day。它也只返回一个元素,因为ID是唯一的,因此您可以使用WebDriver.FindElement

IWebElement element = WebDriver.FindElement(By.Id("lastdays_days"));
相关问题