Selenium Webdriver How to handle radio boxes and multi-marquee

Source: Internet
Author: User
Tags xpath

Perhaps you will encounter the same problem, using the Selenium IDE to record a radio box or a multi-box, in the script, if you want to choose different cases, depending on the use case, select the various boxes or multi-box business process, how to maintain in the Webdriver code? Here are two simple ways to handle this:

Method One:

Webelement select = Dirver.findelement (By.xpath ("//selenium")); list<webelement> alloptions = select.findelements (by.tagname ("option")); for (Webelement option:alloptions) {  System.out.println (String.Format ("Value is:%s", Option.getvalue ()));  If (option.getvalue () = = "Guangzhou") {     option.setselected ();}  }


Method Two:

Select select = New Select (Driver.findelement (By.xpath ("//select")); Select.deselectall (); Select.selectbyvisibletext ("Guangzhou");

In the code, the first select element of the page is selected, all the radio boxes are deselected, and a single box with the text "Guangzhou" is selected.
Obviously, the second method runs more efficiently than the first because the first method also iterates through all the radio elements.

As an example of a single box, it can be used as a way to solve the problem of multi-marquee.

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.