Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/test/chromedriver/element_commands.cc

Issue 13981003: [chromedriver] Wait for the element to be visible before SendKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/chromedriver/test_expectations » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/chromedriver/element_commands.h" 5 #include "chrome/test/chromedriver/element_commands.h"
6 6
7 #include <list> 7 #include <list>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/threading/platform_thread.h"
15 #include "base/time.h"
14 #include "base/values.h" 16 #include "base/values.h"
15 #include "chrome/test/chromedriver/basic_types.h" 17 #include "chrome/test/chromedriver/basic_types.h"
16 #include "chrome/test/chromedriver/chrome/chrome.h" 18 #include "chrome/test/chromedriver/chrome/chrome.h"
17 #include "chrome/test/chromedriver/chrome/js.h" 19 #include "chrome/test/chromedriver/chrome/js.h"
18 #include "chrome/test/chromedriver/chrome/status.h" 20 #include "chrome/test/chromedriver/chrome/status.h"
19 #include "chrome/test/chromedriver/chrome/ui_events.h" 21 #include "chrome/test/chromedriver/chrome/ui_events.h"
20 #include "chrome/test/chromedriver/chrome/web_view.h" 22 #include "chrome/test/chromedriver/chrome/web_view.h"
21 #include "chrome/test/chromedriver/element_util.h" 23 #include "chrome/test/chromedriver/element_util.h"
22 #include "chrome/test/chromedriver/session.h" 24 #include "chrome/test/chromedriver/session.h"
23 #include "chrome/test/chromedriver/util.h" 25 #include "chrome/test/chromedriver/util.h"
24 #include "third_party/webdriver/atoms.h" 26 #include "third_party/webdriver/atoms.h"
25 27
26 namespace { 28 namespace {
27 29
28 Status SendKeysToElement( 30 Status SendKeysToElement(
29 Session* session, 31 Session* session,
30 WebView* web_view, 32 WebView* web_view,
31 const std::string& element_id, 33 const std::string& element_id,
32 const ListValue* key_list) { 34 const ListValue* key_list) {
33 bool is_displayed = false; 35 bool is_displayed = false;
34 Status status = IsElementDisplayed( 36 base::Time start_time = base::Time::Now();
35 session, web_view, element_id, true, &is_displayed); 37 while (true) {
36 if (status.IsError()) 38 Status status = IsElementDisplayed(
37 return status; 39 session, web_view, element_id, true, &is_displayed);
38 if (!is_displayed) 40 if (status.IsError())
39 return Status(kElementNotVisible); 41 return status;
42 if (is_displayed)
43 break;
44 if ((base::Time::Now() - start_time).InMilliseconds() >=
45 session->implicit_wait) {
46 return Status(kElementNotVisible);
47 }
48 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
49 }
40 bool is_enabled = false; 50 bool is_enabled = false;
41 status = IsElementEnabled(session, web_view, element_id, &is_enabled); 51 Status status = IsElementEnabled(session, web_view, element_id, &is_enabled);
42 if (status.IsError()) 52 if (status.IsError())
43 return status; 53 return status;
44 if (!is_enabled) 54 if (!is_enabled)
45 return Status(kInvalidElementState); 55 return Status(kInvalidElementState);
46 base::ListValue args; 56 base::ListValue args;
47 args.Append(CreateElement(element_id)); 57 args.Append(CreateElement(element_id));
48 scoped_ptr<base::Value> result; 58 scoped_ptr<base::Value> result;
49 status = web_view->CallFunction( 59 status = web_view->CallFunction(
50 session->GetCurrentFrameId(), kFocusScript, args, &result); 60 session->GetCurrentFrameId(), kFocusScript, args, &result);
51 if (status.IsError()) 61 if (status.IsError())
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 WebView* web_view, 427 WebView* web_view,
418 const std::string& element_id, 428 const std::string& element_id,
419 const base::DictionaryValue& params, 429 const base::DictionaryValue& params,
420 scoped_ptr<base::Value>* value) { 430 scoped_ptr<base::Value>* value) {
421 std::string other_element_id; 431 std::string other_element_id;
422 if (!params.GetString("other", &other_element_id)) 432 if (!params.GetString("other", &other_element_id))
423 return Status(kUnknownError, "'other' must be a string"); 433 return Status(kUnknownError, "'other' must be a string");
424 value->reset(new base::FundamentalValue(element_id == other_element_id)); 434 value->reset(new base::FundamentalValue(element_id == other_element_id));
425 return Status(kOk); 435 return Status(kOk);
426 } 436 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/chromedriver/test_expectations » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698