selenium找不到页面

时间:2017-02-12 12:40:33

标签: php selenium phpunit

使用Modelizer / Selenium包运行PHP,Laravel和Selenium。我有一个简单的形式(用LaravelCollective制作),没有隐藏的元素或花哨的JavaScript。

表格和测试代码发布在下面。

我得到了

1) can_search_by_city::testCanSearchByCity
Modelizer\Selenium\Exceptions\CannotFindElement: Cannot find element: Search by City isn't visible on the page

我已经审核了所有类似的问题。没有什么不是针对另一个问题的超级特定。

这是我的代码,然后是我的表格......

    $this->visit('/login')
        ->type($this->User->email, 'email')
        ->type('secret', 'password')
        ->press('Login')
        ->see('Searches')
        ->type('queensbury ny','address')
        ->type('100','distance')
        ->wait(20)
        ->click('Search by City')
        ->see('Glens Falls #81')
    ;
}

然后我的表格......

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>    Welcome
 - Elk RV Parking</title>

    <!-- Fonts -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" integrity="sha384-XdYbMnZ/QjLh6iI4ogqCTaIjrFk87ip+ekIjefZch0Y+PvJ8CDYtEs1ipDmPorQ+" crossorigin="anonymous">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700">

    <!-- Styles -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

    <style>
        body {
            font-family: 'Lato';
        }

        .fa-btn {
            margin-right: 6px;
        }
    </style>
</head>
<body id="app-layout">
    <nav class="navbar navbar-default navbar-static-top">
        <div class="container">
            <div class="navbar-header">

                <!-- Collapsed Hamburger -->
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
                    <span class="sr-only">Toggle Navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <!-- Branding Image -->
                <a class="navbar-brand" href="http://localhost:8000">
                    Elk RV Parking
                </a>
            </div>

            <div class="collapse navbar-collapse" id="app-navbar-collapse">
                <!-- Left Side Of Navbar -->
                <ul class="nav navbar-nav">
                    <li><a href="http://localhost:8000/home">Home</a></li>
                </ul>

                <!-- Right Side Of Navbar -->
                <ul class="nav navbar-nav navbar-right">
                    <!-- Authentication Links -->
                                            <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                                Ed Greenberg <span class="caret"></span>
                            </a>

                            <ul class="dropdown-menu" role="menu">
                                <li><a href="http://localhost:8000/logout"><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>
                            </ul>
                        </li>
                                    </ul>
            </div>
        </div>
    </nav>

            <div class="container">
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-heading">Welcome to Elk RV Parking</div>

                    <div class="panel-body">

                        <h1>Searches</h1>
                        <h2>by distance from a city or address</h2>
                        <form method="POST" action="http://localhost:8000/search/address" accept-charset="UTF-8" id="search-by-city"><input name="_token" type="hidden" value="CBphF66rzzk3MbYiNpLK2EsC1jxqVAt6XwRQA9vo">
                        <input name="_token" type="hidden" value="CBphF66rzzk3MbYiNpLK2EsC1jxqVAt6XwRQA9vo">

                        <div class="row">
                            <div class="col-md-8">Enter a city, state, a state, an address, anything that Google Maps would properly search</div>
                            <div class="col=md-4">Distance</div>
                        </div>
                        <div class="row">
                            <div class="col-md-8"><input size="50" name="address" type="text" value=""></div>
                            <div class="col=md-4"><input name="distance" type="text"></div>
                        </div>
                        <div>
                            <div><input type="submit" value="Search by City"></div>
                        </div>
                        </form>

                        <h2>byLodge Number</h2>
                        <form method="POST" action="http://localhost:8000/search/lodgenumber" accept-charset="UTF-8" id="search-by-lodge-number"><input name="_token" type="hidden" value="CBphF66rzzk3MbYiNpLK2EsC1jxqVAt6XwRQA9vo">
                        <input name="_token" type="hidden" value="CBphF66rzzk3MbYiNpLK2EsC1jxqVAt6XwRQA9vo">

                        <div class="row">
                            <div class="col-md-8">Enter a lodge number</div>
                        </div>
                        <div class="row">
                            <div class="col-md-8"><input size="10" name="lodge_number" type="text" value=""></div>
                        </div>
                        <div class="row">
                            <div class="col-md-8"><input type="submit" value="Search by Lodge Number"></div>
                        </div>
                        </form>



                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- JavaScripts -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js" integrity="sha384-I6F5OKECLVtK/BL+8iSLDEHowSAfUo76ZL9+kGAgTRdiByINKJaqTPH/QVNS1VDb" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
    </body>
</html>

我的理解是Selenium通过它的价值来寻找元素。在这种情况下,&#34;按城市搜索&#34;。我不明白为什么它不可见。

1 个答案:

答案 0 :(得分:-1)

您可能希望使用 API执行所需的操作。因为,根据Modelizer / Laravel-Selenium wiki上提供的信息,单击会查找锚标记的名称,ID或文本属性。因此,您可以尝试以下方法:

 extension IneedToDoStuffHere{


 }