summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/web_element_id.h
blob: 55cfd8afd00a9d2eab8f7f7f0294409cbdb77fae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_WEBDRIVER_WEB_ELEMENT_ID_H_
#define CHROME_TEST_WEBDRIVER_WEB_ELEMENT_ID_H_
#pragma once

#include <string>

class Value;

namespace webdriver {

// This class represents a WebDriver WebElement ID. These IDs are mapped to
// objects in a page in JavaScript.
class WebElementId {
 public:
  // Creates an invalid WebElementId.
  WebElementId();

  // Creates a valid |WebElementId| using the ID of an element. An empty string
  // can be used to refer to the root document of the page.
  explicit WebElementId(const std::string& id);

  // Creates a |WebElementId| from an element dictionary returned by a WebDriver
  // atom. It will be valid iff the dictionary is correctly constructed.
  explicit WebElementId(Value* value);

  ~WebElementId();

  // Returns the appropriate |Value| type to be used to identify the element
  // to a WebDriver atom. The client takes ownership.
  Value* ToValue() const;

  // Returns whether this ID is valid. Even if the ID is valid, it may not refer
  // to a valid ID on the page.
  bool is_valid() const;

 private:
  std::string id_;
  bool is_valid_;
};

// WebDriver element locators. These constants are used to identify different
// ways to locate an element to WebDriver atoms. Struct is used for grouping
// purposes.
struct LocatorType {
  static const char kClassName[];
  static const char kCss[];
  static const char kId[];
  static const char kLinkText[];
  static const char kName[];
  static const char kPartialLinkText[];
  static const char kTagName[];
  static const char kXpath[];
};

}  // namespace webdriver

#endif  // CHROME_TEST_WEBDRIVER_WEB_ELEMENT_ID_H_