Selenium Webdriver Installation guide for Ruby _c language

Source: Internet
Author: User

Selenium 1.x era is far away, it should lie in the corner of history, by the fireplace roast fire, smoking Hanyan, in the curl of the rising smoke in the memories of that once belonged to their beautiful times.

But that is not the case, today should be retired early selenium 1.x is still the majority of the firm choice, the reason is only the 1.x era left a large number of documents, code, tutorial let people mistakenly think 1.x or the mainstream of this era, but also should be bright in the foreground performance belongs to its beautiful. Changjiang, the first wave of selenium 1.x's fate should be dead on the beach.

OK, straight into the theme, because the open source community no longer maintain selenium 1.x plus more advanced Selenium 2.0 do have a lot of advantages of the beginning can completely replace 1.x, where I will spend some ink, a number of pages, for a simple explanation selenium 2.0 of some basic knowledge, common methods and advanced expansion, but because the author's level and time and energy, and so is really limited, the text should not avoid fallacies and assumptions, but also hope that the readers a lot of Haihan.

In this article, the code and examples are written by Ruby, and the Webdriver API described in this article is mainly ruby binding. So first make sure that the Ruby language is installed correctly on the development environment.

The first section of the tutorial starts with the relationship between Selenium 2.0 and Webdriver.

What is the relationship between Selenium 2.0 and Webdriver, and what are the skeletons in the closet? It's a long story, but it's simple. Selenium 2.0 is actually webdriver. Just as Zhang Fei is Zhang Yide, Guan Yu is Guanyunchang, but the content is the same.
Install selenium Webdriver

    • Install ruby1.8.7 or 1.9.2. Note that Selenium-webdriver only supports Ruby versions above 1.8.7;
    • Install selenium-webdriver using Gems; Open the command line and enter the following code to complete the installation. Note that if your development environment requires HTTP proxy, please note that the –http_proxy parameter is added to the Gem command;
    • Gem install Selenium-webdriver [--http_proxy]
    • Enter the Gem list on the command line, and if the Selenium-webdriver is installed correctly, it should appear in the results list. In text writing, the latest version of selenium Webdriver should be 2.2.0;
  Gem List Selenium-webdriver

Install Firefox. This article uses Firefox as a test browser to explain, so make sure that Firefox is installed correctly on the development environment. As the Firefox version is updated faster, we only need to select 1 stable version of the installation can be, the author used in this article is FF 5.0;

The simple google test

Here we write a few lines of code in the first time to feel the charm of webdriver, well, to tell the truth the original selenium webdriver does not have any unique charm, contrary to the watir-webdriver more approachable and old. This is not the scope of the text discussion.

Require ' RubyGems '
require ' selenium-webdriver '

driver = Selenium::webdriver.for:firefox
Driver.navigate.to "http://google.com" sleep
3

element = driver.find_element (: name, ' Q ')
Element.send_ Keys "Hello webdriver!"
Element.submit

puts Driver.title

driver.quit

If all goes well, these lines of code will open the Firefox browser and then jump to the Google home page. Wait 3 seconds to enter Hello Webdriver in the search box and submit your search results to the background. Then print the title of the current page at the command line and close the FF browser.

If your code does not run smoothly, please check it from the following sections.

    • Ruby version is 1.8.7 or above and properly installed;
    • Whether the code is require ' RubyGems ';
    • Whether the correct installation of selenium webdriver;
    • Whether the code input is incorrect;

The installation of Selenium-webdriver Ruby binding is actually very simple and fast, and a slightly ruby based reader should be able to do it on its own.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.