<commit_before>/*
Copyright 2007-2009 WebDriver committers
Copyright 2007-2009 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package org.openqa.selenium.ie;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.IllegalLocatorException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.FindsByClassName;
import org.openqa.selenium.internal.FindsById;
import org.openqa.selenium.internal.FindsByLinkText;
import org.openqa.selenium.internal.FindsByName;
import org.openqa.selenium.internal.FindsByTagName;
import org.openqa.selenium.internal.FindsByXPath;

import com.sun.jna.Pointer;
import com.sun.jna.WString;
import com.sun.jna.ptr.PointerByReference;

// Kept package level deliberately.

class Finder implements SearchContext, FindsByClassName, FindsById, FindsByLinkText, FindsByName,
        FindsByTagName, FindsByXPath {

  private final ExportedWebDriverFunctions lib;
  private final InternetExplorerDriver parent;
  private final Pointer driver;
  private final Pointer element;

  public Finder(ExportedWebDriverFunctions lib, InternetExplorerDriver parent, Pointer element) {
    this.lib = lib;
    this.parent = parent;
    this.driver = parent.getUnderlyingPointer();
    this.element = element;
  }

  public WebElement findElementByClassName(String using) {
    if (using == null)
     throw new IllegalArgumentException("Cannot find elements when the class name expression is null.");

    if (using.matches(".*\\s+.*")) {
      throw new IllegalLocatorException(
          "Compound class names are not supported. Consider searching for one class name and filtering the results.");
    }

    PointerByReference rawElement = new PointerByReference();
    int result = lib.wdFindElementByClassName(driver, element, new WString(using), rawElement);

    handleErrorCode("id", using, result);

    return new InternetExplorerElement(lib, parent, rawElement.getValue());
  }

  public List<WebElement> findElementsByClassName(String using) {
    if (using == null)
     throw new IllegalArgumentException("Cannot find elements when the class name expression is null.");

    if (using.matches(".*\\s+.*")) {
      throw new IllegalLocatorException(
          "Compound class names are not supported. Consider searching for one class name and filtering the results.");
    }

    PointerByReference elements = new PointerByReference();
    int result = lib.wdFindElementsByClassName(driver, element, new WString(using), elements);

    handleErrorCode("id", using, result);

    return new ElementCollection(lib, parent, elements.getValue()).toList();
  }

  public WebElement findElementById(String using) {
    PointerByReference rawElement = new PointerByReference();
    int result = lib.wdFindElementById(driver, element, new WString(using), rawElement);

    handleErrorCode("id", using, result);

    return new InternetExplorerElement(lib, parent, rawElement.getValue());
  }

  public List<WebElement> findElementsById(String using) {
    PointerByReference elements = new PointerByReference();
    int result = lib.wdFindElementsById(driver, element, new WString(using), elements);<commit_msg>DanielWagnerHall: Fixing exception message when finding element by class name fails in IE, closing issue #386<commit_after>/*
Copyright 2007-2009 WebDriver committers
Copyright 2007-2009 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package org.openqa.selenium.ie;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.IllegalLocatorException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.FindsByClassName;
import org.openqa.selenium.internal.FindsById;
import org.openqa.selenium.internal.FindsByLinkText;
import org.openqa.selenium.internal.FindsByName;
import org.openqa.selenium.internal.FindsByTagName;
import org.openqa.selenium.internal.FindsByXPath;

import com.sun.jna.Pointer;
import com.sun.jna.WString;
import com.sun.jna.ptr.PointerByReference;

// Kept package level deliberately.

class Finder implements SearchContext, FindsByClassName, FindsById, FindsByLinkText, FindsByName,
        FindsByTagName, FindsByXPath {

  private final ExportedWebDriverFunctions lib;
  private final InternetExplorerDriver parent;
  private final Pointer driver;
  private final Pointer element;

  public Finder(ExportedWebDriverFunctions lib, InternetExplorerDriver parent, Pointer element) {
    this.lib = lib;
    this.parent = parent;
    this.driver = parent.getUnderlyingPointer();
    this.element = element;
  }

  public WebElement findElementByClassName(String using) {
    if (using == null)
     throw new IllegalArgumentException("Cannot find elements when the class name expression is null.");

    if (using.matches(".*\\s+.*")) {
      throw new IllegalLocatorException(
          "Compound class names are not supported. Consider searching for one class name and filtering the results.");
    }

    PointerByReference rawElement = new PointerByReference();
    int result = lib.wdFindElementByClassName(driver, element, new WString(using), rawElement);

    handleErrorCode("class name", using, result);

    return new InternetExplorerElement(lib, parent, rawElement.getValue());
  }

  public List<WebElement> findElementsByClassName(String using) {
    if (using == null)
     throw new IllegalArgumentException("Cannot find elements when the class name expression is null.");

    if (using.matches(".*\\s+.*")) {
      throw new IllegalLocatorException(
          "Compound class names are not supported. Consider searching for one class name and filtering the results.");
    }

    PointerByReference elements = new PointerByReference();
    int result = lib.wdFindElementsByClassName(driver, element, new WString(using), elements);

    handleErrorCode("class name", using, result);

    return new ElementCollection(lib, parent, elements.getValue()).toList();
  }

  public WebElement findElementById(String using) {
    PointerByReference rawElement = new PointerByReference();
    int result = lib.wdFindElementById(driver, element, new WString(using), rawElement);

    handleErrorCode("id", using, result);

    return new InternetExplorerElement(lib, parent, rawElement.getValue());
  }

  public List<WebElement> findElementsById(String using) {
    PointerByReference elements = new PointerByReference();
    int result = lib.wdFindElementsById(driver, element, new WString(using), elements);
{'fraction_non_alphanumeric': 0.08627913066247708, 'fraction_numerical': 0.005629746006808065, 'mean_word_length': 4.7522590361445785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2553376', 'n_tokens_mistral': 2115, 'n_tokens_neox': 2010, 'n_words': 656}