Best Selenium code snippet using org.openqa.selenium.remote.RemoteWebElement.clear
Source:BasicOperation.java
...34 information1Button.click();35 }36 catch(Exception e){37 }38 page.xpathNameList.clear();39 try {40 Thread.sleep(1000);41 } catch (InterruptedException e) {42 e.printStackTrace();43 }44 }while(!informationButtonXpath.equalsIgnoreCase("can not find xpath"));45 Reporter.log("[Login MOSAIQ][Info] current it's on \'Login\' UI");46 page.xpathNameList.clear();47 page.xpathAutomationIdList.clear();48 page.getXpathNameList( driver.getPageSource());49 page.getXpathAutomationIdList( driver.getPageSource());50 String userLoginXpath = page.getXpathByAutomationId("textEditUsername");51 org.openqa.selenium.remote.RemoteWebElement userLoginText = driver.findElementByXPath(userLoginXpath);52 userLoginText.sendKeys(mosaiq_username);53 Reporter.log("[Login MOSAIQ][Text Input] send username on \'Login\' UI");54 String passwordLoginXpath = page.getXpathByName("PasswordTextEdit");55 org.openqa.selenium.remote.RemoteWebElement passwordLoginText = driver.findElementByXPath(passwordLoginXpath);56 passwordLoginText.sendKeys(mosaiq_password);57 Reporter.log("[Login MOSAIQ][Text Input] send password on \'Login\' UI");58 String buttonLoginXpath = page.getXpathByName("&Login");59 org.openqa.selenium.remote.RemoteWebElement buttonLogin = driver.findElementByXPath(buttonLoginXpath);60 buttonLogin.click();61 String maxWimdowInTitle = page.getXpathByName("Maximize");62 if(!maxWimdowInTitle.equalsIgnoreCase("can not find xpath")){63 org.openqa.selenium.remote.RemoteWebElement maxWimdowInTitleElement = driver.findElementByXPath(maxWimdowInTitle);64 maxWimdowInTitleElement.click();65 Reporter.log("[Login MOSAIQ][Button Click] Click \'MaxWindow\' Button");66 }67 Reporter.log("[Login MOSAIQ][Button Click] Login successfully");68 try {69 Thread.sleep(2000);70 } catch (InterruptedException e) {71 e.printStackTrace();72 }73 return true;74 }75 public void getScreenShot(String screenshotFileName){76 try {77 Thread.sleep(5000);78 } catch (InterruptedException e) {79 e.printStackTrace();80 }81 File file = driver.getScreenshotAs(OutputType.FILE);82 File destination=new File(screenshotFileName);83 try{84 FileUtils.copyFile(file, destination);85 }86 catch(Exception e){87 }88 }89 // TODO Auto-generated method stub:90 // This Method is to 'Register Patient' in MOSAIQ.91 public boolean registerPatient(String lastName, String firstName, String patientID){92 Reporter.log("---------------------------MOSAIQ : start to register patient---------------------------");93 try {94 Thread.sleep(3000);95 } catch (InterruptedException e) {96 e.printStackTrace();97 }98 PageSource page = new PageSource();99 page.xpathNameList.clear();100 page.xpathAutomationIdList.clear();101 page.getXpathNameList( driver.getPageSource());102 String fileLableInTitle = page.getXpathByName("File");103 org.openqa.selenium.remote.RemoteWebElement fileLableInTitleElement = driver.findElementByXPath(fileLableInTitle);104 fileLableInTitleElement.click();105 Reporter.log("[RegisterPatient][Button Click] Click \'File\' Button");106 try {107 Thread.sleep(3000);108 } catch (InterruptedException e) {109 e.printStackTrace();110 }111 page.xpathNameList.clear();112 page.xpathAutomationIdList.clear();113 page.getXpathNameList( driver.getPageSource());114 String registerPatientInMenu = page.getXpathByName("Register New Patient...");115 org.openqa.selenium.remote.RemoteWebElement registerPatientInMenuElement = driver.findElementByXPath(registerPatientInMenu);116 registerPatientInMenuElement.click();117 Reporter.log("[RegisterPatient][Button Click] Click \'Register New Patient...\' Button");118 try {119 Thread.sleep(3000);120 } catch (InterruptedException e) {121 e.printStackTrace();122 }123 // find "New Patient" window124 String currentHandle = driver.getWindowHandle();125 Set<String> handles = driver.getWindowHandles();126 for(String handle:handles ){127 if (!currentHandle.equals(handle) ) {128 driver.switchTo().window(handle);129 }130 }131 page.xpathNameList.clear();132 page.xpathAutomationIdList.clear();133 page.getXpathAutomationIdList( driver.getPageSource());134 String patientLastName = page.getXpathByAutomationId("textLastName");135 org.openqa.selenium.remote.RemoteWebElement patientLastNameElement = driver.findElementByXPath(patientLastName);136 patientLastNameElement.sendKeys(lastName);137 Reporter.log("[RegisterPatient][Test Input] input \'Last Name\' for patient");138 String patientFirstName = page.getXpathByAutomationId("textFirstName");139 org.openqa.selenium.remote.RemoteWebElement patientFirstNameElement = driver.findElementByXPath(patientFirstName);140 patientFirstNameElement.sendKeys(firstName);141 Reporter.log("[RegisterPatient][Test Input] input \'First Name\' for patient");142 String patientId = page.getXpathByAutomationId("textIDA");143 org.openqa.selenium.remote.RemoteWebElement patientIdElement = driver.findElementByXPath(patientId);144 patientIdElement.sendKeys(patientID);145 Reporter.log("[RegisterPatient][Test Input] input \'Patient ID\' for patient");146 page.getXpathNameList( driver.getPageSource());147 String physicianName = page.getXpathByName("&Physicians/Diagnosis");148 org.openqa.selenium.remote.RemoteWebElement physicianNameElement = driver.findElementByXPath(physicianName);149 physicianNameElement.click();150 Reporter.log("[RegisterPatient][Button Click] Click \'&Physicians/Diagnosis\' Button");151 try {152 Thread.sleep(3000);153 } catch (InterruptedException e) {154 e.printStackTrace();155 }156 page.getXpathAutomationIdList( driver.getPageSource()) ;157 String attendPhysicianEdit = page.getXpathByAutomationId("inputAttendingPhysician");158 String attendPhysicianEditButton = attendPhysicianEdit+"/Button[@LocalizedControlType=\"button\"]";159 org.openqa.selenium.remote.RemoteWebElement attendPhysicianEditButtonElement = driver.findElementByXPath(attendPhysicianEditButton);160 attendPhysicianEditButtonElement.click();161 try {162 Thread.sleep(3000);163 } catch (InterruptedException e) {164 e.printStackTrace();165 }166 page.xpathNameList.clear();167 page.xpathAutomationIdList.clear();168 page.getXpathNameList( driver.getPageSource());169 String physicianSelect = page.getXpathByName("Row 1");170 org.openqa.selenium.remote.RemoteWebElement physicianSelectElement = driver.findElementByXPath(physicianSelect);171 physicianSelectElement.click();172 Reporter.log("[RegisterPatient][Button Click] Click the first one \'Physicians\' ");173 String selectButton = page.getXpathByNameAndAttribution("[@Name=\"Select\"]","/Button");174 org.openqa.selenium.remote.RemoteWebElement selectButtonElement = driver.findElementByXPath(selectButton);175 selectButtonElement.click();176 Reporter.log("[RegisterPatient][Button Click] Click \'Select\' Button in \'Select Physicians\' window");177 String saveButton = page.getXpathByName("Save");178 org.openqa.selenium.remote.RemoteWebElement saveButtonElement = driver.findElementByXPath(saveButton);179 saveButtonElement.click();180 Reporter.log("[RegisterPatient][Button Click] Click \'Save\' Button in \'Select Physicians\' window");181 try {182 Thread.sleep(3000);183 } catch (InterruptedException e) {184 e.printStackTrace();185 }186 page.xpathNameList.clear();187 page.xpathAutomationIdList.clear();188 page.getXpathNameList( driver.getPageSource());189 String noButton = page.getXpathByNameAndAttribution("[@Name=\"&No\"]","/Button");190 org.openqa.selenium.remote.RemoteWebElement noButtonElement = driver.findElementByXPath(noButton);191 noButtonElement.click();192 Reporter.log("[RegisterPatient][Button Click] Click \'No\' Button in \'No Duplicate Patients Found\' window");193 try {194 Thread.sleep(3000);195 } catch (InterruptedException e) {196 e.printStackTrace();197 }198 return true;199 }200 public void importTreatmentPlan(String planPath){201 try {202 Thread.sleep(5000);203 } catch (InterruptedException e) {204 e.printStackTrace();205 }206 Set<String> handles = driver.getWindowHandles();207 if(handles.size()==1)208 driver.switchTo().window(handles.iterator().next());209 PageSource page = new PageSource();210 page.xpathNameList.clear();211 page.xpathAutomationIdList.clear();212 page.getXpathNameList( driver.getPageSource());213 String fileLableInTitle = page.getXpathByName("File");214 org.openqa.selenium.remote.RemoteWebElement fileLableInTitleElement = driver.findElementByXPath(fileLableInTitle);215 fileLableInTitleElement.click();216 try {217 Thread.sleep(3000);218 } catch (InterruptedException e) {219 e.printStackTrace();220 }221 page.xpathNameList.clear();222 page.xpathAutomationIdList.clear();223 page.getXpathNameList( driver.getPageSource());224 String importInMenu = page.getXpathByName("Import/Export");225 org.openqa.selenium.remote.RemoteWebElement importInMenuElement = driver.findElementByXPath(importInMenu);226 importInMenuElement.click();227 try {228 Thread.sleep(3000);229 } catch (InterruptedException e) {230 e.printStackTrace();231 }232 page.xpathNameList.clear();233 page.xpathAutomationIdList.clear();234 page.getXpathNameList( driver.getPageSource());235 String importPlanInMenu = page.getXpathByName("Ion Plan Import...");236 org.openqa.selenium.remote.RemoteWebElement importPlanInMenuElement = driver.findElementByXPath(importPlanInMenu);237 importPlanInMenuElement.click();238 }239 // TODO Auto-generated method stub:240 // This Method is to finish 'Plan Promote' in MOSAIQ.241 public void promotePlan(){242 Reporter.log("---------------------------MOSAIQ : start to Promote Plan---------------------------");243 try {244 Thread.sleep(3000);245 } catch (InterruptedException e) {246 e.printStackTrace();247 }248 String currentHandle = driver.getWindowHandle();249 Set<String> handles = driver.getWindowHandles();250 for(String handle:handles ){251 if (!currentHandle.equals(handle) ) {252 driver.switchTo().window(handle);253 }254 }255 PageSource page = new PageSource();256 page.xpathNameList.clear();257 page.xpathAutomationIdList.clear();258 page.getXpathNameList( driver.getPageSource());259 String DAndIButton = page.getXpathByNameAndAttribution("[@Name=\"D and I\"]","/Button");260 org.openqa.selenium.remote.RemoteWebElement DAndIButtonElement = driver.findElementByXPath(DAndIButton);261 DAndIButtonElement.click();262 Reporter.log("[Promote Plan][Button Click] Click \'D and I\' Button");263 try {264 Thread.sleep(1000);265 } catch (InterruptedException e) {266 e.printStackTrace();267 }268 page.xpathNameList.clear();269 page.xpathAutomationIdList.clear();270 page.getXpathNameList( driver.getPageSource());271 String promoteButton = page.getXpathByNameAndAttribution("[@Name=\"Promote\"]","/Button");272 org.openqa.selenium.remote.RemoteWebElement promoteButtonElement = driver.findElementByXPath(promoteButton);273 promoteButtonElement.click();274 Reporter.log("[Promote Plan][Button Click] Click \'Promote\' Button");275 }276 // TODO Auto-generated method stub:277 // This Method is to select patient when the patient exists.278 public boolean selectPatient(String patientName){279 Reporter.log("---------------------------MOSAIQ : start to Select Patient when the patient exists---------------------------");280 try {281 Thread.sleep(3000);282 } catch (InterruptedException e) {283 e.printStackTrace();284 }285 PageSource page = new PageSource();286 page.xpathNameList.clear();287 page.xpathAutomationIdList.clear();288 page.getXpathNameList(driver.getPageSource());289 String fileLableInTitle = page.getXpathByName("File");290 org.openqa.selenium.remote.RemoteWebElement fileLableInTitleElement = driver.findElementByXPath(fileLableInTitle);291 fileLableInTitleElement.click();292 Reporter.log("[SelectPatient][Button Click] Click \'File\' Button");293 try {294 Thread.sleep(1000);295 } catch (InterruptedException e) {296 e.printStackTrace();297 }298 page.xpathNameList.clear();299 page.xpathAutomationIdList.clear();300 page.getXpathNameList( driver.getPageSource());301 String patientInList = page.getXpathByName(patientName);302 org.openqa.selenium.remote.RemoteWebElement patientInListElement = driver.findElementByXPath(patientInList);303 patientInListElement.click();304 Reporter.log("[SelectPatient][Button Click] Click Patient Name Item");305 return true;306 }307 // TODO Auto-generated method stub:308 // This Method is to add machine in File-Directories-Location Directory.309 public boolean addMachineInLocationDirectory(String machineName) {310 Reporter.log("---------------------------MOSAIQ : start to add machine in Location Directory---------------------------");311 try {312 Thread.sleep(6000);313 } catch (InterruptedException e) {314 e.printStackTrace();315 }316 driver.switchTo().window(driver.getWindowHandle());317 PageSource page = new PageSource();318 System.out.println(driver.getCapabilities());319 page.getXpathNameList( driver.getPageSource());320 String fileLableInTitle = page.getXpathByName("File");321 org.openqa.selenium.remote.RemoteWebElement fileLableInTitleElement = driver.findElementByXPath(fileLableInTitle);322 fileLableInTitleElement.click();323 Reporter.log("[Add Machine In Location Directory][Button Click] Click \'File\' Button");324 try {325 Thread.sleep(1000);326 } catch (InterruptedException e) {327 e.printStackTrace();328 }329 page.xpathNameList.clear();330 page.xpathAutomationIdList.clear();331 page.getXpathNameList( driver.getPageSource());332 String directorisInMenu = page.getXpathByName("Directories");333 org.openqa.selenium.remote.RemoteWebElement directorisElement = driver.findElementByXPath(directorisInMenu);334 directorisElement.click();335 Reporter.log("[Add Machine In Location Directory][Button Click] Click \'Directories\' BUtton");336 try {337 Thread.sleep(1000);338 } catch (InterruptedException e) {339 e.printStackTrace();340 }341 page.xpathNameList.clear();342 page.xpathAutomationIdList.clear();343 page.getXpathNameList( driver.getPageSource());344 String locationDirectorisInMenu = page.getXpathByName("Location Directory...");345 org.openqa.selenium.remote.RemoteWebElement locationDirectorisInMenuElement = driver.findElementByXPath(locationDirectorisInMenu);346 locationDirectorisInMenuElement.click();347 Reporter.log("[Add Machine In Location Directory][Button Click] Click \'Location Directory...\' BUtton");348 try {349 Thread.sleep(3000);350 } catch (InterruptedException e) {351 e.printStackTrace();352 }353 String currentHandle = driver.getWindowHandle();354 Set<String> handles = driver.getWindowHandles();355 for(String handle:handles ){356 if (!currentHandle.equals(handle) ) {357 driver.switchTo().window(handle);358 }359 }360 ArrayList<String> machineList = machineListInLocation(page);361 NumOfMachine = machineList.indexOf(machineName);362 page.xpathNameList.clear();363 page.xpathAutomationIdList.clear();364 page.getXpathNameList( driver.getPageSource());365 if(!machineList.contains(machineName)){366 Reporter.log("[Add Machine In Location Directory] need to add machine "+machineName);367 String addButton = page.getXpathByName("Add");368 org.openqa.selenium.remote.RemoteWebElement addButtonElement = driver.findElementByXPath(addButton);369 addButtonElement.click();370 Reporter.log("[Add Machine In Location Directory][Button Click] Click \'Add\' BUtton");371 try {372 Thread.sleep(3000);373 } catch (InterruptedException e) {374 e.printStackTrace();375 }376 page.xpathNameList.clear();377 page.xpathAutomationIdList.clear();378 page.getXpathNameList(driver.getPageSource());379 page.getXpathAutomationIdList( driver.getPageSource());380 String nameText = page.getXpathByAutomationId("textEditName");381 org.openqa.selenium.remote.RemoteWebElement nameTextElement = driver.findElementByXPath(nameText);382 nameTextElement.sendKeys(machineName);383 Reporter.log("[Add Machine In Location Directory][Input Text] Input machine name");384 String categorySelect = page.getXpathByAutomationIdAndAttribution("lookUpCategory","/Edit");385 org.openqa.selenium.remote.RemoteWebElement categorySelectElement = driver.findElementByXPath(categorySelect);386 categorySelectElement.sendKeys("Accelerator");387 Reporter.log("[Add Machine In Location Directory][Input Text] Input machine category");388 String typeSelect = page.getXpathByAutomationIdAndAttribution("lookUpType","/Edit");389 org.openqa.selenium.remote.RemoteWebElement typeSelectElement = driver.findElementByXPath(typeSelect);390 typeSelectElement.sendKeys("Radiation Oncology");391 Reporter.log("[Add Machine In Location Directory][Input Text] Input machine type");392 String saveButton = page.getXpathByName("Save");393 org.openqa.selenium.remote.RemoteWebElement saveButtonElement = driver.findElementByXPath(saveButton);394 saveButtonElement.click();395 Reporter.log("[Add Machine In Location Directory][Button Click] Click \'Save\' Button");396 TestingListener.driver = driver;397 try {398 Thread.sleep(3000);399 } catch (InterruptedException e) {400 e.printStackTrace();401 }402 page.xpathNameList.clear();403 page.xpathAutomationIdList.clear();404 page.getXpathNameList(driver.getPageSource());405 String closeButton = page.getXpathByName("Close");406 org.openqa.selenium.remote.RemoteWebElement closeButtonElement = driver.findElementByXPath(closeButton);407 closeButtonElement.click();408 Reporter.log("[Add Machine In Location Directory][Button Click] Click \'Close\' Button");409 }410 else{411 Reporter.log("[Add Machine In Location Directory] machine "+machineName+"has existed.");412 String closeButton = page.getXpathByName("Close");413 org.openqa.selenium.remote.RemoteWebElement closeButtonElement = driver.findElementByXPath(closeButton);414 closeButtonElement.click();415 }416 try {417 Thread.sleep(3000);418 } catch (InterruptedException e) {419 e.printStackTrace();420 }421 return true;422 }423 // TODO Auto-generated method stub:424 // This Method is to output all machines in File-Directories-Location Directory.425 public ArrayList<String> machineListInLocation(PageSource page){426 ArrayList<String> machineList = new ArrayList<String>();427 page.xpathNameList.clear();428 page.xpathAutomationIdList.clear();429 page.getXpathNameList( driver.getPageSource());430 String machine = "";431 int i=0;432 do {433 machine = page.getXpathByName("Machine row "+i);434 if(!machine.equalsIgnoreCase("can not find xpath")){435 org.openqa.selenium.remote.RemoteWebElement machineListElement = driver.findElementByXPath(machine);436 machineList.add(machineListElement.getText());}437 i++;438 }while(!machine.equalsIgnoreCase("can not find xpath"));439 System.out.println("");440 return machineList;441 }442// // TODO Auto-generated method stub:443// // This Method is to output all machines in File-System Utilities-Mahcine Characterization.444// public ArrayList<String> machineListInMachineCharacterization(PageSource page){445// ArrayList<String> machineList = new ArrayList<String>();446// page.xpathNameList.clear();447// page.xpathAutomationIdList.clear();448// page.getXpathByName(driver.getPageSource());449// page.getXpathAutomationIdList(driver.getPageSource());450// String thumbMachine = page.getXpathByAutomationId("DownPageButton");451// org.openqa.selenium.remote.RemoteWebElement thumbMachineElement = driver.findElementByXPath(thumbMachine);452// thumbMachineElement.sendKeys("ttttttt");453// thumbMachineElement.click();454// thumbMachineElement.getLocation();455// String machine = thumbMachineElement.getText();456//// page.xpathNameList.clear();457//// page.xpathAutomationIdList.clear();458//// page.getXpathByName(driver.getPageSource());459//460// return machineList;461// }462 // TODO Auto-generated method stub:463 // This Method is to update/add machine characterization.464 public boolean updateMachineCharacterization(String machineName) {465 Reporter.log("---------------------------MOSAIQ : start to add machine characterization---------------------------");466 try {467 Thread.sleep(3000);468 } catch (InterruptedException e) {469 e.printStackTrace();470 }471 String currentHandle = driver.getWindowHandle();472 Set<String> handles = driver.getWindowHandles();473 for (String handle : handles) {474 if (!currentHandle.equals(handle)) {475 driver.switchTo().window(handle);476 }477 }478 PageSource page = new PageSource();479 page.xpathNameList.clear();480 page.xpathAutomationIdList.clear();481 page.getXpathNameList(driver.getPageSource());482 String maxWimdowInTitle = page.getXpathByName("Maximize");483 if(!maxWimdowInTitle.equalsIgnoreCase("can not find xpath")){484 org.openqa.selenium.remote.RemoteWebElement maxWimdowInTitleElement = driver.findElementByXPath(maxWimdowInTitle);485 maxWimdowInTitleElement.click();486 Reporter.log("[Machine Characterization][Button Click] Click \'MaxWindow\' Button");487 }488 String fileLableInTitle = page.getXpathByName("File");489 org.openqa.selenium.remote.RemoteWebElement fileLableInTitleElement = driver.findElementByXPath(fileLableInTitle);490 fileLableInTitleElement.click();491 Reporter.log("[Machine Characterization][Button Click] Click \'File\' Button");492 try {493 Thread.sleep(1000);494 } catch (InterruptedException e) {495 e.printStackTrace();496 }497 page.xpathNameList.clear();498 page.xpathAutomationIdList.clear();499 page.getXpathNameList(driver.getPageSource());500 String systemUtilitiesInMenu = page.getXpathByName("System Utilities");501 org.openqa.selenium.remote.RemoteWebElement systemUtilitiesInMenuElement = driver.findElementByXPath(systemUtilitiesInMenu);502 systemUtilitiesInMenuElement.click();503 Reporter.log("[Machine Characterization][Button Click] Click \'System Utilities\' Button");504 try {505 Thread.sleep(1000);506 } catch (InterruptedException e) {507 e.printStackTrace();508 }509 page.xpathNameList.clear();510 page.xpathAutomationIdList.clear();511 page.getXpathNameList(driver.getPageSource());512 String machineCharacterizationInMenu = page.getXpathByName("Machine Characterization...");513 org.openqa.selenium.remote.RemoteWebElement machineCharacterizationInMenuElement = driver.findElementByXPath(machineCharacterizationInMenu);514 machineCharacterizationInMenuElement.click();515 Reporter.log("[Add Machine In Location Directory][Button Click] Click \'Machine Characterization...\' BUtton");516 try {517 Thread.sleep(3000);518 } catch (InterruptedException e) {519 e.printStackTrace();520 }521 currentHandle = driver.getWindowHandle();522 handles = driver.getWindowHandles();523 for (String handle : handles) {524 if (!currentHandle.equals(handle)) {525 driver.switchTo().window(handle);526 }527 }528 page.xpathNameList.clear();529 page.xpathAutomationIdList.clear();530 page.getXpathNameList(driver.getPageSource());531 String addButton = page.getXpathByName("Add");532 org.openqa.selenium.remote.RemoteWebElement addButtonElement = driver.findElementByXPath(addButton);533 addButtonElement.click();534 Reporter.log("[Machine Characterization][Button Click] Click \'Add\' Button");535 try {536 Thread.sleep(3000);537 } catch (InterruptedException e) {538 e.printStackTrace();539 }540 currentHandle = driver.getWindowHandle();541 handles = driver.getWindowHandles();542 for (String handle : handles) {543 if (!currentHandle.equals(handle)) {544 driver.switchTo().window(handle);545 }546 }547 page.xpathNameList.clear();548 page.xpathAutomationIdList.clear();549 page.getXpathNameList(driver.getPageSource());550 page.getXpathAutomationIdList(driver.getPageSource());551 String typeText = page.getXpathByName("[@ClassName=\"ClaDrop_01000000H\"][@Name=\"Type:\"]");552 org.openqa.selenium.remote.RemoteWebElement typeTextElement = driver.findElementByXPath(typeText);553 typeTextElement.click();554 try {555 Robot robot = new Robot();556 robot.keyPress(KeyEvent.VK_DOWN);// Here is KeyEvent.VK_DOWN rather than KeyEvent.VK_PAGE_DOWN557 robot.keyPress(KeyEvent.VK_ENTER);558 robot.keyRelease(KeyEvent.VK_ENTER);559 robot.keyRelease(KeyEvent.VK_DOWN);560 } catch (AWTException e) {561 e.printStackTrace();562 }563 try {564 Thread.sleep(3000);565 } catch (InterruptedException e) {566 e.printStackTrace();567 }568 page.xpathNameList.clear();569 page.xpathAutomationIdList.clear();570 page.getXpathNameList(driver.getPageSource());571 String machineText = page.getXpathByName("[@ClassName=\"ClaDrop_01000000H\"][@Name=\"Machine:\"]");572 org.openqa.selenium.remote.RemoteWebElement machineTextElement = driver.findElementByXPath(machineText);573 machineTextElement.click();574 try {575 Thread.sleep(3000);576 } catch (InterruptedException e) {577 e.printStackTrace();578 }579 page.xpathNameList.clear();580 page.xpathAutomationIdList.clear();581 page.getXpathNameList(driver.getPageSource());582 Robot robot = null;583 try {584 robot = new Robot();585 } catch (AWTException e) {586 e.printStackTrace();587 }588 for(int i=0;i<=5;i++){ // TODO; it should be NumOfMachine.589 robot.keyPress(KeyEvent.VK_DOWN);// Here is KeyEvent.VK_DOWN rather than KeyEvent.VK_PAGE_DOWN590 robot.keyRelease(KeyEvent.VK_DOWN);591 }592 robot.keyPress(KeyEvent.VK_ENTER);593 robot.keyRelease(KeyEvent.VK_ENTER);594 Reporter.log("[Machine Characterization][Choose Machine] choose machine");595 String allButton = page.getXpathByName("All");596 org.openqa.selenium.remote.RemoteWebElement allButtonElement = driver.findElementByXPath(allButton);597 allButtonElement.click();598 Reporter.log("[Machine Characterization][Button Click] Click button \'All\'");599 String okButton = page.getXpathByName("OK");600 org.openqa.selenium.remote.RemoteWebElement okButtonElement = driver.findElementByXPath(okButton);601 okButtonElement.click();602 Reporter.log("[Machine Characterization][Button Click] Click button \'OK\'");603 String importButton = page.getXpathByName("Import");604 org.openqa.selenium.remote.RemoteWebElement importButtonElement = driver.findElementByXPath(importButton);605 importButtonElement.click();606 Reporter.log("[Machine Characterization][Button Click] Click button \'Import\'");607 try {608 Thread.sleep(3000);609 } catch (InterruptedException e) {610 e.printStackTrace();611 }612 currentHandle = driver.getWindowHandle();613 handles = driver.getWindowHandles();614 for (String handle : handles) {615 if (!currentHandle.equals(handle)) {616 driver.switchTo().window(handle);617 }618 }619 page.xpathNameList.clear();620 page.xpathAutomationIdList.clear();621 page.getXpathNameList(driver.getPageSource());622 page.getXpathAutomationIdList(driver.getPageSource());623 String macPathEdit = page.getXpathByNameAndAttribution("Path:","/Edit");624 org.openqa.selenium.remote.RemoteWebElement macPathEditElement = driver.findElementByXPath(macPathEdit);625 ForSendKeys(macPathEditElement, HelloMosaiq_Case1.CaseRootPath);626 macPathEditElement.clear();627 macPathEditElement.sendKeys(HelloMosaiq_Case1.CaseRootPath);628 Reporter.log("[Machine Characterization][Input Text] Input MAC file path");629 String spaceClick = page.getXpathByAutomationId("16398");630 org.openqa.selenium.remote.RemoteWebElement spaceClickElement = driver.findElementByXPath(spaceClick);631 spaceClickElement.click();632 try {633 Thread.sleep(3000);634 } catch (InterruptedException e) {635 e.printStackTrace();636 }637 page.xpathNameList.clear();638 page.xpathAutomationIdList.clear();639 page.getXpathNameList(driver.getPageSource());640 page.getXpathAutomationIdList(driver.getPageSource());641 String fileClick = page.getXpathByAutomationIdAndAttribution("16393","/Pane");642 org.openqa.selenium.remote.RemoteWebElement fileClickElement = driver.findElementByXPath(fileClick);643 fileClickElement.click();644 robot.keyPress(KeyEvent.VK_DOWN);// Here is KeyEvent.VK_DOWN rather than KeyEvent.VK_PAGE_DOWN645 robot.keyRelease(KeyEvent.VK_DOWN);646 String okClick = page.getXpathByName("OK");647 org.openqa.selenium.remote.RemoteWebElement okClickElement = driver.findElementByXPath(okClick);648 okClickElement.click();649 try {650 Thread.sleep(2000);651 } catch (InterruptedException e) {652 e.printStackTrace();653 }654 String changeButton = page.getXpathByName("Change");655 org.openqa.selenium.remote.RemoteWebElement changeButtonElement = driver.findElementByXPath(changeButton);656 changeButtonElement.click();657 Reporter.log("[Machine Characterization][Button Click] Click button \'Change\'");658 page.xpathNameList.clear();659 page.xpathAutomationIdList.clear();660 page.getXpathNameList( driver.getPageSource());661 page.getXpathAutomationIdList(driver.getPageSource());662 String informationButtonXpath = page.getXpathByName("OK");663 org.openqa.selenium.remote.RemoteWebElement informationButtonXpathElement = driver.findElementByXPath(informationButtonXpath);664 informationButtonXpathElement.click();665 String machinetemplateName="";666 int count=0;667 do{668// click reference;669 currentHandle = driver.getWindowHandle();670 handles = driver.getWindowHandles();671 for (String handle : handles) {672 if (!currentHandle.equals(handle)) {673 driver.switchTo().window(handle);674 }675 }676 page.xpathNameList.clear();677 page.xpathAutomationIdList.clear();678 page.getXpathNameList(driver.getPageSource());679 page.getXpathAutomationIdList(driver.getPageSource());680 String referenceButton = page.getXpathByNameAndAttribution("Reference","/Button");681 org.openqa.selenium.remote.RemoteWebElement referenceButtonElement = driver.findElementByXPath(referenceButton);682 referenceButtonElement.click();683 Reporter.log("[Machine Characterization][Button Click] Click button \'Reference\'");684 Robot keyboard = null;685 try {686 keyboard = new Robot();687 } catch (AWTException e) {688 e.printStackTrace();689 }690 for(int i=0;i<=count;i++) {691 keyboard.keyPress(KeyEvent.VK_DOWN);692 keyboard.keyRelease(KeyEvent.VK_DOWN);693 try {694 Thread.sleep(100);695 } catch (InterruptedException e) {696 e.printStackTrace();697 }698 }699 robot.keyPress(KeyEvent.VK_ENTER);700 robot.keyRelease(KeyEvent.VK_ENTER);701 count++;702 machinetemplateName = currentTemplateName(page);703 System.out.println("Current Template is "+machinetemplateName);704 }while(!machinetemplateName.equalsIgnoreCase(machineName));705 //delete all706 String deleteAllButton = page.getXpathByAutomationIdAndAttribution("16441","/Button"); //????707 org.openqa.selenium.remote.RemoteWebElement deleteAllButtonElement = driver.findElementByXPath(deleteAllButton);708 deleteAllButtonElement.click();709 try {710 Thread.sleep(1000);711 } catch (InterruptedException e) {712 e.printStackTrace();713 }714 //copy all715 String copyAllButton = page.getXpathByAutomationIdAndAttribution("16435","/Button"); //????716 org.openqa.selenium.remote.RemoteWebElement copyAllButtonElement = driver.findElementByXPath(copyAllButton);717 copyAllButtonElement.click();718 try {719 Thread.sleep(2000);720 } catch (InterruptedException e) {721 e.printStackTrace();722 }723 String okChangeMachineButton = page.getXpathByName("OK"); //????724 org.openqa.selenium.remote.RemoteWebElement okChangeMachineButtonElement = driver.findElementByXPath(okChangeMachineButton);725 okChangeMachineButtonElement.click();726 page.xpathNameList.clear();727 page.xpathAutomationIdList.clear();728 page.getXpathNameList( driver.getPageSource());729 page.getXpathAutomationIdList(driver.getPageSource());730 informationButtonXpath = page.getXpathByName("OK");731 informationButtonXpathElement = driver.findElementByXPath(informationButtonXpath);732 informationButtonXpathElement.click();733 String closeButton = page.getXpathByName("Close"); //????734 org.openqa.selenium.remote.RemoteWebElement closeButtonElement = driver.findElementByXPath(closeButton);735 closeButtonElement.click();736 return true;737 }738 public static void ForSendKeys(RemoteWebElement element, String content){739 for (int i = 0; i < content.length(); i++) {740 element.sendKeys(content.charAt(i)+"");741 }742 }743 public String currentTemplateName(PageSource page){744 String machineTemplateName = "";745 String currentHandle = driver.getWindowHandle();746 Set<String> handles = driver.getWindowHandles();747 for (String handle : handles) {748 if (!currentHandle.equals(handle)) {749 driver.switchTo().window(handle);750 }751 }752 page.xpathNameList.clear();753 page.xpathAutomationIdList.clear();754 page.getXpathNameList(driver.getPageSource());755 page.getXpathAutomationIdList(driver.getPageSource());756 String currentReferenceType = page.getXpathByAutomationIdAndAttribution("16445","/Edit"); //????757 org.openqa.selenium.remote.RemoteWebElement currentReferenceTypeElement = driver.findElementByXPath(currentReferenceType);758 machineTemplateName = currentReferenceTypeElement.getText();759 return machineTemplateName;760 }761}...
Source:RemoteWebElementWrapper.java
...399 original.sendKeys(keysToSend);400 }401 /**402 * 403 * @see org.openqa.selenium.remote.RemoteWebElement#clear()404 */405 @Override406 public void clear() {407 original.clear();408 }409 /**410 * @return411 * @see org.openqa.selenium.remote.RemoteWebElement#isSelected()412 */413 @Override414 public boolean isSelected() {415 return original.isSelected();416 }417 /**418 * @return419 * @see org.openqa.selenium.remote.RemoteWebElement#isEnabled()420 */421 @Override...
Source:W3CHttpCommandCodec.java
...206 "var source = document.documentElement.outerHTML; \n" +207 "if (!source) { source = new XMLSerializer().serializeToString(document); }\n" +208 "return source;");209 case CLEAR_LOCAL_STORAGE:210 return toScript("localStorage.clear()");211 case GET_LOCAL_STORAGE_KEYS:212 return toScript("return Object.keys(localStorage)");213 case SET_LOCAL_STORAGE_ITEM:214 return toScript("localStorage.setItem(arguments[0], arguments[1])",215 parameters.get("key"), parameters.get("value"));216 case REMOVE_LOCAL_STORAGE_ITEM:217 return toScript("var item = localStorage.getItem(arguments[0]); localStorage.removeItem(arguments[0]); return item",218 parameters.get("key"));219 case GET_LOCAL_STORAGE_ITEM:220 return toScript("return localStorage.getItem(arguments[0])", parameters.get("key"));221 case GET_LOCAL_STORAGE_SIZE:222 return toScript("return localStorage.length");223 case CLEAR_SESSION_STORAGE:224 return toScript("sessionStorage.clear()");225 case GET_SESSION_STORAGE_KEYS:226 return toScript("return Object.keys(sessionStorage)");227 case SET_SESSION_STORAGE_ITEM:228 return toScript("sessionStorage.setItem(arguments[0], arguments[1])",229 parameters.get("key"), parameters.get("value"));230 case REMOVE_SESSION_STORAGE_ITEM:231 return toScript("var item = sessionStorage.getItem(arguments[0]); sessionStorage.removeItem(arguments[0]); return item",232 parameters.get("key"));233 case GET_SESSION_STORAGE_ITEM:234 return toScript("return sessionStorage.getItem(arguments[0])", parameters.get("key"));235 case GET_SESSION_STORAGE_SIZE:236 return toScript("return sessionStorage.length");237 case IS_ELEMENT_DISPLAYED:238 return executeAtom("isDisplayed.js", asElement(parameters.get("id")));...
Source:EyesAppiumElement.java
...152 public void submit() {153 webElement.submit();154 }155 @Override156 public void clear() {157 webElement.clear();158 }159 @Override160 public String getTagName() {161 return webElement.getTagName();162 }163 @Override164 public String getAttribute(String name) {165 return webElement.getAttribute(name);166 }167 @Override168 public boolean isSelected() {169 return webElement.isSelected();170 }171 @Override...
Source:OperationInDCMtree.java
...21 Thread.sleep(1000);22 } catch (InterruptedException e) {23 e.printStackTrace();24 }25 page.xpathNameList.clear();26 page.getXpathNameList( driver.getPageSource());27 String addClickXpath = page.getXpathByName("Add...");28 org.openqa.selenium.remote.RemoteWebElement addClickXpathButton = driver.findElementByXPath(addClickXpath);29 addClickXpathButton.click();30 Reporter.log("[Button Click] \'Add...\' Button click in DCMTree window");31 try {32 Thread.sleep(3000);33 } catch (InterruptedException e) {34 e.printStackTrace();35 }36 page.xpathNameList.clear();37 page.getXpathNameList( driver.getPageSource());38 String fileNameEditClickXpath = page.getXpathByNameAndAttribution("[@ClassName=\"Edit\"][@Name=\"File name:\"]","/Edit");39 org.openqa.selenium.remote.RemoteWebElement fileNameEditXpathText = driver.findElementByXPath(fileNameEditClickXpath);40 fileNameEditXpathText.sendKeys(planPath);41 Reporter.log("[Text Input] Input plan path in Open window");42 String openClickXpath = page.getXpathByNameAndAttribution("[@ClassName=\"Button\"][@Name=\"Open\"]","/Button");43 org.openqa.selenium.remote.RemoteWebElement openClickXpathButton = driver.findElementByXPath(openClickXpath);44 openClickXpathButton.click();45 Reporter.log("[Button Click] \'Open\' Button click in Open window");46 try {47 Thread.sleep(1000);48 } catch (InterruptedException e) {49 e.printStackTrace();50 }51 fileClickXpathButton.click();52 Reporter.log("[Button Click] \'File\' Button click in DCMTree window");53 page.xpathNameList.clear();54 page.getXpathNameList( driver.getPageSource());55 String transmitClickXpath = page.getXpathByName("Transmit...");56 org.openqa.selenium.remote.RemoteWebElement transmitClickXpathButton = driver.findElementByXPath(transmitClickXpath);57 transmitClickXpathButton.click();58 Reporter.log("[Button Click] \'Transmit...\' Button click in DCMTree window");59 String currentHandle1 = driver.getWindowHandle();60 Set<String> handles1= driver.getWindowHandles();61 for(String handle:handles1 ){62 if (!currentHandle1.equals(handle) ) {63 driver.switchTo().window(handle);64 }65 }66 page.xpathNameList.clear();67 page.getXpathNameList( driver.getPageSource());68 String sendClickXpath = page.getXpathByNameAndAttribution("[@Name=\"Send\"]","/Button");69 org.openqa.selenium.remote.RemoteWebElement sendClickXpathButton = driver.findElementByXPath(sendClickXpath);70 sendClickXpathButton.click();71 Reporter.log("[Button Click] \'Send\' Button click in \'Send DICOM File\' window");72 try {73 Thread.sleep(1000);74 } catch (InterruptedException e) {75 e.printStackTrace();76 }77 if(sendClickXpath.equalsIgnoreCase("can not find xpath"))78 return false;79 else80 return true;...
Source:GoogleHomePage.java
...24 }25 }26 public void enterSearchCriteria(String palabra){27 28 googleInput().clear();29// getFluentWait().until(ExpectedConditions.visibilityOfElementLocated(By.xpath(LocatorManager.getProperty("googleHome.searchButton.xpath"))));30// driver.findElement(By.xpath(LocatorManager.getProperty("googleHome.searchButton.xpath")));31 googleInput().sendKeys(palabra);32 }33 public void clickSearchButton(){34 googleInput().sendKeys(Keys.ENTER);35 }36}...
clear
Using AI Code Generation
1import java.net.MalformedURLException;2import java.net.URL;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.RemoteWebElement;8import org.openqa.selenium.remote.RemoteWebDriver;9public class ClearMethod {10public static void main(String[] args) throws MalformedURLException, InterruptedException {11 DesiredCapabilities cap = new DesiredCapabilities();12 cap.setBrowserName("chrome");13 cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);14 WebElement email = driver.findElement(By.id("email"));15 RemoteWebElement re = (RemoteWebElement) email;16 re.clear();17 re.sendKeys("Selenium");18 Thread.sleep(5000);19 driver.quit();20}21}22Related Posts: How to use sendKeys() method in Selenium WebDriver23How to use clear() method in Selenium WebDriver24How to use isDisplayed() method in Selenium WebDriver25How to use isEnabled() method in Selenium WebDriver26How to use isSelected() method in Selenium WebDriver27How to use getAttribute() method in Selenium WebDriver28How to use getCssValue() method in Selenium WebDriver29How to use getTagName() method in Selenium WebDriver30How to use getText() method in Selenium WebDriver31How to use getSize() method in Selenium WebDriver32How to use getLocation() method in Selenium WebDriver33How to use getRect() method in Selenium WebDriver34How to use getScreenshotAs() method in Selenium WebDriver35How to use getCoordinates() method in Selenium WebDriver36How to use getCapabilities() method in Selenium WebDriver37How to use getWindowHandle() method in Selenium WebDriver38How to use getWindowHandles() method in Selenium WebDriver39How to use getCurrentUrl() method in Selenium WebDriver40How to use getPageSource() method in Selenium WebDriver41How to use getTitle() method in Selenium WebDriver42How to use findElement() method in Selenium WebDriver43How to use findElements() method in Selenium WebDriver44How to use get() method in Selenium WebDriver45How to use getCurrentUrl() method in Selenium WebDriver46How to use getPageSource() method in Selenium WebDriver
clear
Using AI Code Generation
1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5public class ClearMethod {6 public static void main(String[] args) {7 System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Downloads\\chromedriver_win32\\chromedriver.exe");8 WebDriver driver = new ChromeDriver();9 driver.get(baseUrl);10 WebElement email = driver.findElement(By.id("email")); 11 WebElement password = driver.findElement(By.name("passwd")); 12 email.sendKeys("
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!