[Selenium] The commonly used operation of element

btnLogin.click();     //Click element

SeleniumUtil.jsClick(driver, saveButtonEl);     //If click()  is not applicable ,try this one

txtEmail.clear();     //Clear text box before send keys to it

txtEmail.sendKeys(“jenny.zhang@morningstar.com”);     //Send keys to text box

emailEl.getAttribute("title");   //Get attribute value of element

hoverEl.getText();      //Get text of element

SeleniumUtil.scrollIntoView(driver, el);       //Scroll the element into view if the function needs scroll bar or mouse wheel when manual testing

//Click a hidden element

action.moveToElement(pencilIcon).click();

//Before click an element under a hidden element

locx=(theRow.getSize().width)/100;

locy=(theRow.getSize().height)/2;

action.moveToElement(theRow, locx, locy);

//Get text of hidden element

String dataPointName = (String) ((JavascriptExecutor) driver).executeScript(

                   "return jQuery(arguments[0]).text();", element);

//Ctrl+click

Actions a = new Actions(driver);

a.keyDown(Keys.CONTROL).perform();

for(int i = 0;i<quantity;i++){

     WebElement securityEl = securitiesList.get(i);

      SeleniumUtil.scrollIntoView(driver, securityEl);

      securityEl.click();

 }

a.keyUp(Keys.CONTROL).perform();

//Drag and drop

Point targetWidgetPos = targetWidgetEl.getLocation();

Point widgetPos = widgetEl.getLocation();

int offsetX = targetWidgetPos.getX() - widgetPos.getX();

int offsetY = targetWidgetPos.getY() - widgetPos.getY();

SeleniumUtil.dragAndDropOffset(driver, titleEl, offsetX, offsetY);

原文地址:https://www.cnblogs.com/feifeidxl/p/4450535.html