Selenium 2 Java uses select to process drop-down box examples

Keywords: Programming Java Linux Selenium

In learning selenium 2 java, I encountered a drop-down box when I wrote the use case of the receiving address. I just practiced the use of select. Now I share it for your reference.

	//Delete Add Receiving Address
	public static void deleteAndAddUserAdress(WebDriver driver) throws InterruptedException {
		clickUser(driver);
		findElementByTextAndClick(driver, "Personal information");
		findElementByTextAndClick(driver, "Receiving address");
		clickDeleteAdress(driver);
		sleep(0);
		clickSure(driver);
		AddAddress(driver);
		String name = getTextByXpath(driver, ".//*[@id='main']/div[2]/div/div/div[1]/p[1]");
		assertTrue("Failed to add harvest address!", name.equals("Consignee:Test consignee"));
	}

The following is a specific way to add the receiving address:

//Add Receiving Address
	public static void AddAdress(WebDriver driver) {
		findElementByIdAndClick(driver, "add-address-btn");//Click Add Address
		findElementByXpathAndClearSendkeys(driver, ".//* [@id='LAY_layuipro1a']/div/div[1]/table/tbody/tr[1]/td[2]/div/input,""Test consignee";//Add consignee"
		findElementByXpathAndClearSendkeys(driver, ".//*[@id='LAY_layuipro1a']/div/div[1]/table/tbody/tr[2]/td[2]/div/input "," 13120454218 "; / / input cell phone number
		//Selection of provinces, cities and counties, and detailed addresses
		Select province = new Select(findElementByid(driver, "province-select"));
		province.selectByIndex(1);
		Select city = new Select(findElementByid(driver, "city-select"));
		city.selectByIndex(1);			
		Select area = new Select(findElementByid(driver, "area-select"));
		area.selectByIndex(1);
		findElementByClassnameAndClearSendkeys(driver, "textarea", "I'm the test address.");
		clickSave(driver);
	}

Selection of previous articles

  1. One line of java code prints a heart
  2. Linux performance monitoring software netdata Chinese version
  3. Interface Test Code Coverage (jacoco) Scheme Sharing
  4. Performance testing framework
  5. How to Enjoy Performance Testing on Linux Command Line Interface
  6. Graphic HTTP Brain Map
  7. Writing to everyone about programming thinking
  8. How to Test Probabilistic Business Interface
  9. httpclient handles multi-user simultaneous online
  10. Ten Steps to Become a Great Java Developer
  11. Automatically convert swagger documents into test code
  12. Five lines of code to build static blogs
  13. How httpclient handles 302 redirection

Public Number Map ☢️ Together ~FunTester

Posted by coolphpdude on Tue, 01 Oct 2019 16:08:54 -0700