Selenium common commands for manipulating page elements and organizing events to get element content

/**id <input type=”text” id=”phone” name=”phone” class=”LoginText” placeholder=”手机号” >
* <button class=”LoginBtn” id=”btnLogin” value=”baidu”> 登录</button>*/

WebElement byName=driver.findElement(By.name("phone")); 
WebElement byLoginButton=driver.findElement(By.id("btnLogin")); 
System.out.println(byName.getText());

 

1. The click() event originates from the click element operation

byLoginButton.click();

2. The sendKeys() method is used to assign a value to the input element

byName.sendKeys("13600000000");

3. clear() is used to clear the value of the input element

byName.clear();

4. Submit() is used to submit the form

 byLoginButton.submit();

5. getTitle() gets the title of the current web page

String title=driver.getTitle();

6. getCurrentUrl() gets the URL of the current web page

 String url=driver.getCurrentUrl();

 

7. getText() is used to store the text value of the element, such as plain text, hyperlinks, etc.;

 String text=byName.getText();

 

8. isSelected() is used to store the check box or radio check box, and returns true (checked) or false (unchecked)

 /**<input id="TANGRAM__PSP_8__memberPass" type="checkbox" name="memberPass" class="pass-checkbox-input pass-checkbox-memberPass" checked="checked">*/
 WebElement checkBox=driver.findElement(By.id("TANGRAM__PSP_8__memberPass"));
 boolean isSelected=checkBox.isSelected();

 

9. getTagName() gets the tag name of the element

 String tagName=byName.getTagName();

 

10. isEnabled() is used to store the editable state of elements such as input, such as: text boxes, checkboxes, radio buttons; returns true (editable) or false (not editable)

 boolean enabled=checkBox.isEnabled();

 

11. getAttribute() is used to obtain the value of the specified attribute

 String btnValue=byLoginButton.getAttribute("value");

 

12. Maximize the window

 driver.manage().window().maximize(); 

 

13. The accept() method is to click the confirmation button of the pop-up dialog box, for example: Alert, Confirmation, Prompt

 driver.switchTo().alert().accept();

 

14. The dismiss() method realizes clicking the cancel button of the pop-up dialog box;

 driver.switchTo().alert().dismiss();

 

15. getText() gets the text content of the pop-up dialog

 driver.switchTo().alert().getText();

 

16. Get the current set of cookies

 Set<Cookie> cookie=driver.manage().getCookies();

 

17. refresh() page refresh

 driver.navigate().refresh();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324840230&siteId=291194637