を使用したInvalidElementStateException以下のコードはIE、FireFox、Chromeで完璧に実行されます。 PhantomJSでは、ポップアップ(divのCSSスタイリングを介して)が表示されるため、この場合は待機していないようです。例外が発生したステートメントの前にsleepステートメントを置くと、問題はなくなります。なぜdriver.ImplicitlyWait()は動作しませんか?私は睡眠と私のコードを捨てる必要はありませんファントムと私は待つ必要がありますか?PhantomJS 2.1.1/Webdriver 2.53.0およびVisual Studio/C#
私は多くの投稿を見てきましたが、誰も私の問題を解決していないようです。私が何を試すことができるかについてのあらゆる考え?
私が試した事実と事...
- ソースコード全体にid = 'firstname'という要素が1つしかありません。
- この要素はブラウザに関係なく常に検出されますが、これは対話可能な問題です。
- この要素は、常にff、chrome、つまりWebDriverWaitなしで対話可能です。
- WebDriverWaitを使用しない限り、この要素は決してファントムで相互作用できません。
- driver.Manage()。Window.sizeをMaximumまたは1920,1080に設定しても問題は解決されません。
- By.CssSelector( "input#firstname")やBy.XPath( "// div [@ class = 'modal-body'] // input [@ id = 'firstname']」などの異なるセレクタを試行する同じ例外が生じました。
// successful code
IWebDriver driver = new PhantomJSDriver();
driver.Manage().Window.Size = new System.Drawing.Size(1920, 1080);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Navigate().GoToUrl(home_page);
driver.FindElement(By.Id("btnAddEmployee")).Click();
// exception here
driver.FindElement(By.Id("firstname")).SendKeys("first name");
//例外 OpenQA.Selenium.InvalidElementStateException:{ "にErrorMessage": "要素が現在相互作用ではなく、操作されなくてもよい"、 "リクエスト":{ "ヘッダ":{ "受け入れ":」 "Content-Length": "19"、 "Content-Type": "application/json; charset = utf-8"、 "Host": " "localhost:20943"}、 "httpVersion": "1.1"、 "method": "POST"、 "post": "{\" value \ ":[\" alice \ "]}"、 "url": "/" 「値」、「ディレクトリ」、「/」、「パス」:「/値」、「相対」、「値」、「urlParsed」:「アンカー」:「」「問合せ」:「」「ファイル」「値」「ディレクトリ」: : "、"ポート ":" "、"ホスト ":" "、"パスワード ":" "、"ユーザー ":" "、" userInfo ":" "、"権限 ":" "プロトコル"/"、 "source": "/ value"、 "queryKey":{}、 "チャンク":["value"]}、 "urlOriginal": "/ session/5c641300-a229-11e6-9fa8-69dbd56d6ff7 /要素/:wdc:1478220923048 /値 "}} 結果StandardOutput:
リモートサーバーに接続できません OpenQA.Selenium.InvalidElementStateException:{"errorMessage": "要素は現在対話可能ではなく、操作できません"、 "request":{"headers":{" ":"アプリケーション/ json、イメージ/ png "、"接続 ":"閉じる "、" Content-Length ":" 19 "、" Content-Type ":" application/json; charset = utf- ":" localhost:20943 "}、" httpVersion ":" 1.1 "、" method ":" POST "、" post ":" {\ "value \":[\ "alice \"]} "、" url " "/ value"、 "urlParsed":{"アンカー": ""、 "クエリ": ""、 "ファイル": "値"、 "ディレクトリ": "/"、 "パス": "/値" 「相対」:「/値」、「ポート」:「」、「ホスト」:「」、「パスワード」:「」、「ユーザー」:「」、「userInfo」:「」、「権限」: 、 "protocol": ""、 "source": "/ value"、 "queryKey":{}、 "chunk":["value"]}、 "urlOriginal": "/ session/5c641300-a229-11e6-9fa8 -69dbd56d6ff7/element /:wdc:1478220923048/value "}} at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError( OpenQA.Selenium.Remote.RemoteWebDriver.Execute(文字列driverCommandToExecute、Dictionary`2パラメーター) OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(文字列テキスト)の でC:のTest.TestCases.Test()で を返します。プロジェクト\テスト\プロジェクト\ TestCases.cs \ Visual Studioの2015 \ \ Users \ユーザーユーザー\ドキュメント:要素が見えるまで暗黙の待機待機を使用してライン191
// web page source code being automated
<!DOCTYPE html><html lang="en"><head>
<title>Benefits Dashboard</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/pagePuncher.css">
<link href="https://fonts.googleapis.com/css?family=Merriweather+Sans:300" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js">
</script>
<script src="http://fgnass.github.io/spin.js/spin.min.js"></script><style type="text/css"></style>
<script src="assets/js/employee.js"></script>
<script src="assets/js/scripts.js"></script>
<script>
function GetURLParameter(r){for(var t=window.location.search.substring(1),e=t.split("&"),n=0;n<e.length;n++){var a=e[n].split("=");if(a[0]==r)return a[1]}return""}""==GetURLParameter("username")&&(window.location.href="login.html");
</script>
</head>
<body class="modal-open">
<div id="uselessBlueHeader"></div>
<div class="container">
<div id="header" class="page-header jumbotron">
<h1>Benefits Dashboard</h1>
</div>
<div id="data">
<div class="table-responsive">
<table class="table table-striped table-hover" id="employee-table" style="margin-bottom: 5px;">
<thead>
<tr>
<th>ID</th>
<th>Last Name</th>
<th>First Name</th>
<th>Salary</th>
<th>Dependents</th>
<th>Gross Pay
</th><th>Benefit Cost</th>
<th>Net Pay</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<button id="btnAddEmployee" type="button" class="btn btn-primary" data-toggle="modal" data-target="#addEmployeeModal">Add Employee</button>
<div class="modal fade in" id="addEmployeeModal" role="dialog" style="display: block;">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Employee & His dependents</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" id="employees-form" onsubmit="return validateForm()">
<div class="form-group">
<label class="control-label col-sm-2" for="firstname">First Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="firstname">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="lastname">Last Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="lastname">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="dependents">Dependants:</label>
<div class="col-xs-1">
<input type="text" class="form-control" id="dependents">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-primary" data-dismiss="modal" id="addEmployee">Submit</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="modal-backdrop fade in"></div></body></html>
異なるセレクタを使用して要素を検索することができますか? – Abhinav
また、以下を使用してブラウザを最大化しようとすることもできますか?driver.manage()。window()。maximize();私は回避策としてこれを述べているポストを見た。助けてくれたら教えてください。 – Abhinav
あなたのアドバイスをありがとうAbhinav。私はポストを「私が試した事実」で更新しました。あなたの提案は残念ながら問題を解決しませんでした。 – user1701153