How to use RemoteWebElement class of org.openqa.selenium.remote package

Best Selenium code snippet using org.openqa.selenium.remote.RemoteWebElement

Source:BasicOperation.java Github

copy

Full Screen

...5import io.appium.java_client.windows.WindowsDriver;6import io.appium.java_client.windows.WindowsElement;7import org.apache.commons.io.FileUtils;8import org.openqa.selenium.OutputType;9import org.openqa.selenium.remote.RemoteWebElement;10import org.testng.Reporter;11import util.TestReport.TestingListener;12import util.findXpath.PageSource;13import java.awt.*;14import java.awt.event.KeyEvent;15import java.io.File;16import java.io.IOException;17import java.util.ArrayList;18import java.util.Set;19public class BasicOperation {20 public static WindowsDriver<WindowsElement> driver = null;21 public static int NumOfMachine =0;22 // TODO Auto-generated method stub:23 // This Method is to Login MOSAIQ.24 public boolean login(String mosaiq_username, String mosaiq_password) {25 Reporter.log("---------------------------MOSAIQ: start to login---------------------------");26 Reporter.log("[Login MOSAIQ][Button Click] Click \'OK\' Button util login UI show up");27 PageSource page = new PageSource();28 String informationButtonXpath = "";29 do{30 page.getXpathNameList( driver.getPageSource());31 informationButtonXpath = page.getXpathByName("OK");32 try{33 org.openqa.selenium.remote.RemoteWebElement information1Button = driver.findElementByXPath(informationButtonXpath);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}...

Full Screen

Full Screen

Source:RemoteWebElementWrapper.java Github

copy

Full Screen

...40import org.openqa.selenium.WebElement;41import org.openqa.selenium.interactions.internal.Coordinates;42import org.openqa.selenium.remote.FileDetector;43import org.openqa.selenium.remote.RemoteWebDriver;44import org.openqa.selenium.remote.RemoteWebElement;45import com.neotys.selenium.proxies.helpers.ProxySendHelper;46import com.neotys.selenium.proxies.helpers.SeleniumProxyConfig;47import com.neotys.selenium.proxies.helpers.WrapperUtils;48/** We tried to avoid using direct wrapper methods like this, but we found a case where an "instanceof" check was done49 * for a @RemoteWebElement in @org.openqa.selenium.remote.internal.WebElementToJsonConverter#apply(). */50public class RemoteWebElementWrapper extends RemoteWebElement {51 final WebDriver webDriver;52 final SeleniumProxyConfig proxyConfig;53 final ProxySendHelper proxySendHelper;54 final WrapperUtils wrapperUtils;55 final RemoteWebElement original;56 private static final List<String> METHODS_SEND_ON_EXCEPTION_ONLY = WebElementProxy.METHODS_SEND_ON_EXCEPTION_ONLY;57 private static final List<String> METHODS_ALWAYS_SEND = WebElementProxy.METHODS_ALWAYS_SEND;58 public RemoteWebElementWrapper(final WebDriver webDriver, final RemoteWebElement original, final SeleniumProxyConfig proxyConfig){59 this.webDriver = webDriver;60 this.proxyConfig = proxyConfig;61 this.proxySendHelper = new ProxySendHelper(proxyConfig);62 this.wrapperUtils = new WrapperUtils(proxyConfig);63 this.original = original;64 }65 66 @Override67 public void setFileDetector(FileDetector detector) {68 original.setFileDetector(detector);69 }70 71 @Override72 public void setId(String id) {73 original.setId(id);74 }75 76 @Override77 public void setParent(RemoteWebDriver parent) {78 super.setParent(parent);79 original.setParent(parent);80 }81 82 @Override83 public void click() {84 if (!SeleniumProxyConfig.isEnabled()) {85 original.click();86 return;87 }88 try {89 final Method method = RemoteWebElement.class.getDeclaredMethod("click", (Class<?>[])null);90 proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),91 webDriver, original, method, (Object[])null);92 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {93 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);94 }95 }96 @Override97 public void submit() {98 if (!SeleniumProxyConfig.isEnabled()) {99 original.submit();100 return;101 }102 try {103 final Method method = RemoteWebElement.class.getDeclaredMethod("submit", (Class<?>[])null);104 proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),105 webDriver, original, method, (Object[])null);106 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {107 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);108 }109 }110 @Override111 public String getTagName() {112 if (!SeleniumProxyConfig.isEnabled()) {113 return original.getTagName();114 }115 try {116 final Method method = RemoteWebElement.class.getDeclaredMethod("getTagName", (Class<?>[])null);117 return (String) proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),118 webDriver, original, method, (Object[])null);119 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {120 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);121 }122 }123 @Override124 public String getAttribute(final String name) {125 if (!SeleniumProxyConfig.isEnabled()) {126 return original.getAttribute(name);127 }128 try {129 final Method method = RemoteWebElement.class.getDeclaredMethod("getAttribute", (new Class<?>[]{String.class}));130 return (String) proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),131 webDriver, original, method, new Object[]{name});132 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {133 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);134 } 135 }136 @Override137 public List<WebElement> findElements(final By by) {138 if (!SeleniumProxyConfig.isEnabled()) {139 return original.findElements(by);140 }141 try {142 final Method method = RemoteWebElement.class.getDeclaredMethod("findElements", (new Class<?>[]{By.class}));143 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),144 webDriver, original, method, new Object[]{by});145 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {146 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);147 } 148 }149 @Override150 public WebElement findElement(final By by) {151 if (!SeleniumProxyConfig.isEnabled()) {152 return original.findElement(by);153 }154 try {155 final Method method = RemoteWebElement.class.getDeclaredMethod("findElement", (new Class<?>[]{By.class}));156 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),157 webDriver, original, method, new Object[]{by});158 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {159 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);160 } 161 }162 @Override163 public WebElement findElementById(final String using) {164 if (!SeleniumProxyConfig.isEnabled()) {165 return original.findElementById(using);166 }167 try {168 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementById", (new Class<?>[]{String.class}));169 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),170 webDriver, original, method, new Object[]{using});171 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {172 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);173 } 174 }175 @Override176 public List<WebElement> findElementsById(final String using) {177 if (!SeleniumProxyConfig.isEnabled()) {178 return original.findElementsById(using);179 }180 try {181 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsById", (new Class<?>[]{String.class}));182 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),183 webDriver, original, method, new Object[]{using});184 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {185 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);186 } 187 }188 @Override189 public WebElement findElementByLinkText(final String using) {190 if (!SeleniumProxyConfig.isEnabled()) {191 return original.findElementByLinkText(using);192 }193 try {194 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementByLinkText", (new Class<?>[]{String.class}));195 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),196 webDriver, original, method, new Object[]{using});197 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {198 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);199 } 200 }201 @Override202 public List<WebElement> findElementsByLinkText(final String using) {203 if (!SeleniumProxyConfig.isEnabled()) {204 return original.findElementsByLinkText(using);205 }206 try {207 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsByLinkText", (new Class<?>[]{String.class}));208 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),209 webDriver, original, method, new Object[]{using});210 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {211 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);212 } 213 }214 @Override215 public WebElement findElementByName(final String using) {216 if (!SeleniumProxyConfig.isEnabled()) {217 return original.findElementByName(using);218 }219 try {220 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementByName", (new Class<?>[]{String.class}));221 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),222 webDriver, original, method, new Object[]{using});223 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {224 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);225 } 226 }227 @Override228 public List<WebElement> findElementsByName(final String using) {229 if (!SeleniumProxyConfig.isEnabled()) {230 return original.findElementsByName(using);231 }232 try {233 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsByName", (new Class<?>[]{String.class}));234 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),235 webDriver, original, method, new Object[]{using});236 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {237 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);238 } 239 }240 @Override241 public WebElement findElementByClassName(final String using) {242 if (!SeleniumProxyConfig.isEnabled()) {243 return original.findElementByClassName(using);244 }245 try {246 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementByClassName", (new Class<?>[]{String.class}));247 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),248 webDriver, original, method, new Object[]{using});249 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {250 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);251 } 252 }253 @Override254 public List<WebElement> findElementsByClassName(final String using) {255 if (!SeleniumProxyConfig.isEnabled()) {256 return original.findElementsByClassName(using);257 }258 try {259 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsByClassName", (new Class<?>[]{String.class}));260 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),261 webDriver, original, method, new Object[]{using});262 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {263 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);264 } 265 }266 @Override267 public WebElement findElementByCssSelector(final String using) {268 if (!SeleniumProxyConfig.isEnabled()) {269 return original.findElementByCssSelector(using);270 }271 try {272 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementByCssSelector", (new Class<?>[]{String.class}));273 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),274 webDriver, original, method, new Object[]{using});275 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {276 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);277 } 278 }279 @Override280 public List<WebElement> findElementsByCssSelector(final String using) {281 if (!SeleniumProxyConfig.isEnabled()) {282 return original.findElementsByCssSelector(using);283 }284 try {285 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsByCssSelector", (new Class<?>[]{String.class}));286 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),287 webDriver, original, method, new Object[]{using});288 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {289 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);290 } 291 }292 @Override293 public WebElement findElementByXPath(final String using) {294 if (!SeleniumProxyConfig.isEnabled()) {295 return original.findElementByXPath(using);296 }297 try {298 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementByXPath", (new Class<?>[]{String.class}));299 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),300 webDriver, original, method, new Object[]{using});301 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {302 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);303 } 304 }305 @Override306 public List<WebElement> findElementsByXPath(final String using) {307 if (!SeleniumProxyConfig.isEnabled()) {308 return original.findElementsByXPath(using);309 }310 try {311 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsByXPath", (new Class<?>[]{String.class}));312 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),313 webDriver, original, method, new Object[]{using});314 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {315 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);316 } 317 }318 @Override319 public WebElement findElementByPartialLinkText(final String using) {320 if (!SeleniumProxyConfig.isEnabled()) {321 return original.findElementByPartialLinkText(using);322 }323 try {324 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementByPartialLinkText", (new Class<?>[]{String.class}));325 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),326 webDriver, original, method, new Object[]{using});327 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {328 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);329 } 330 }331 @Override332 public List<WebElement> findElementsByPartialLinkText(final String using) {333 if (!SeleniumProxyConfig.isEnabled()) {334 return original.findElementsByPartialLinkText(using);335 }336 try {337 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsByPartialLinkText", (new Class<?>[]{String.class}));338 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),339 webDriver, original, method, new Object[]{using});340 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {341 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);342 } 343 }344 @Override345 public WebElement findElementByTagName(final String using) {346 if (!SeleniumProxyConfig.isEnabled()) {347 return original.findElementByTagName(using);348 }349 try {350 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementByTagName", (new Class<?>[]{String.class}));351 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),352 webDriver, original, method, new Object[]{using});353 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {354 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);355 } 356 }357 @Override358 public List<WebElement> findElementsByTagName(final String using) {359 if (!SeleniumProxyConfig.isEnabled()) {360 return original.findElementsByTagName(using);361 }362 try {363 final Method method = RemoteWebElement.class.getDeclaredMethod("findElementsByTagName", (new Class<?>[]{String.class}));364 return proxySendHelper.sendAndReturn(METHODS_ALWAYS_SEND, METHODS_SEND_ON_EXCEPTION_ONLY, Collections.<String>emptyList(),365 webDriver, original, method, new Object[]{using});366 } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {367 throw new NeotysWrappingException("Issue with NeoLoad proxy.", e);368 } 369 }370 @Override371 public WebDriver getWrappedDriver() {372 if (!SeleniumProxyConfig.isEnabled()) {373 return original.getWrappedDriver();374 }375 return (WebDriver) wrapperUtils.wrapIfNecessary(webDriver, super.getWrappedDriver());376 }377 @Override378 protected Object clone() throws CloneNotSupportedException {379 if (!SeleniumProxyConfig.isEnabled()) {380 return super.clone();381 }382 return wrapperUtils.wrapIfNecessary(webDriver, super.clone());383 }384 // automatically generated wrapper methods --------------------------------------------------------385 /**386 * @return387 * @see org.openqa.selenium.remote.RemoteWebElement#getId()388 */389 @Override390 public String getId() {391 return original.getId();392 }393 /**394 * @param keysToSend395 * @see org.openqa.selenium.remote.RemoteWebElement#sendKeys(java.lang.CharSequence[])396 */397 @Override398 public void sendKeys(CharSequence... keysToSend) {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 @Override422 public boolean isEnabled() {423 return original.isEnabled();424 }425 /**426 * @return427 * @see org.openqa.selenium.remote.RemoteWebElement#getText()428 */429 @Override430 public String getText() {431 return original.getText();432 }433 /**434 * @param propertyName435 * @return436 * @see org.openqa.selenium.remote.RemoteWebElement#getCssValue(java.lang.String)437 */438 @Override439 public String getCssValue(String propertyName) {440 return original.getCssValue(propertyName);441 }442 /**443 * @param obj444 * @return445 * @see org.openqa.selenium.remote.RemoteWebElement#equals(java.lang.Object)446 */447 @Override448 public boolean equals(Object obj) {449 return original.equals(obj);450 }451 /**452 * @return453 * @see org.openqa.selenium.remote.RemoteWebElement#hashCode()454 */455 @Override456 public int hashCode() {457 return original.hashCode();458 }459 /**460 * @return461 * @see org.openqa.selenium.remote.RemoteWebElement#isDisplayed()462 */463 @Override464 public boolean isDisplayed() {465 return original.isDisplayed();466 }467 /**468 * @return469 * @see org.openqa.selenium.remote.RemoteWebElement#getLocation()470 */471 @Override472 public Point getLocation() {473 return original.getLocation();474 }475 /**476 * @return477 * @see org.openqa.selenium.remote.RemoteWebElement#getSize()478 */479 @Override480 public Dimension getSize() {481 return original.getSize();482 }483 /**484 * @return485 * @see org.openqa.selenium.remote.RemoteWebElement#getRect()486 */487 @Override488 public Rectangle getRect() {489 return original.getRect();490 }491 /**492 * @return493 * @see org.openqa.selenium.remote.RemoteWebElement#getCoordinates()494 */495 @Override496 public Coordinates getCoordinates() {497 return original.getCoordinates();498 }499 /**500 * @param outputType501 * @return502 * @throws WebDriverException503 * @see org.openqa.selenium.remote.RemoteWebElement#getScreenshotAs(org.openqa.selenium.OutputType)504 */505 @Override506 public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException {507 return original.getScreenshotAs(outputType);508 }509 /**510 * @return511 * @see org.openqa.selenium.remote.RemoteWebElement#toString()512 */513 @Override514 public String toString() {515 return original.toString();516 }517}...

Full Screen

Full Screen

Source:CustomLocatorHandler.java Github

copy

Full Screen

...32import org.openqa.selenium.remote.CommandExecutor;33import org.openqa.selenium.remote.DriverCommand;34import org.openqa.selenium.remote.HttpSessionId;35import org.openqa.selenium.remote.RemoteWebDriver;36import org.openqa.selenium.remote.RemoteWebElement;37import org.openqa.selenium.remote.Response;38import org.openqa.selenium.remote.ResponseCodec;39import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec;40import org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec;41import org.openqa.selenium.remote.http.AddSeleniumUserAgent;42import org.openqa.selenium.remote.http.Contents;43import org.openqa.selenium.remote.http.HttpHandler;44import org.openqa.selenium.remote.http.HttpMethod;45import org.openqa.selenium.remote.http.HttpRequest;46import org.openqa.selenium.remote.http.HttpResponse;47import org.openqa.selenium.remote.http.Routable;48import org.openqa.selenium.remote.http.UrlTemplate;49import org.openqa.selenium.remote.locators.CustomLocator;50import java.io.IOException;51import java.io.UncheckedIOException;52import java.util.Map;53import java.util.Set;54import java.util.function.Function;55import java.util.stream.Collectors;56import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;57import static org.openqa.selenium.json.Json.MAP_TYPE;58class CustomLocatorHandler implements Routable {59 private static final Json JSON = new Json();60 private static final UrlTemplate FIND_ELEMENT = new UrlTemplate("/session/{sessionId}/element");61 private static final UrlTemplate FIND_ELEMENTS = new UrlTemplate("/session/{sessionId}/elements");62 private static final UrlTemplate FIND_CHILD_ELEMENT = new UrlTemplate("/session/{sessionId}/element/{elementId}/element");63 private static final UrlTemplate FIND_CHILD_ELEMENTS = new UrlTemplate("/session/{sessionId}/element/{elementId}/elements");64 private final HttpHandler toNode;65 private final Map<String, Function<Object, By>> extraLocators;66 // These are derived from the w3c webdriver spec67 private static final Set<String> W3C_STRATEGIES = ImmutableSet.of(68 "css selector",69 "link text",70 "partial link text",71 "tag name",72 "xpath");73 @VisibleForTesting74 CustomLocatorHandler(Node node, Secret registrationSecret, Set<CustomLocator> extraLocators) {75 Require.nonNull("Node", node);76 Require.nonNull("Registration secret", registrationSecret);77 Require.nonNull("Extra locators", extraLocators);78 HttpHandler nodeHandler = node::executeWebDriverCommand;79 this.toNode = nodeHandler.with(new AddSeleniumUserAgent())80 .with(new AddWebDriverSpecHeaders())81 .with(new AddSecretFilter(registrationSecret));82 this.extraLocators = extraLocators.stream()83 .collect(Collectors.toMap(CustomLocator::getLocatorName, locator -> locator::createBy));84 }85 @Override86 public boolean matches(HttpRequest req) {87 if (req.getMethod() != HttpMethod.POST) {88 return false;89 }90 return FIND_ELEMENT.match(req.getUri()) != null ||91 FIND_ELEMENTS.match(req.getUri()) != null ||92 FIND_CHILD_ELEMENT.match(req.getUri()) != null ||93 FIND_CHILD_ELEMENTS.match(req.getUri()) != null;94 }95 @Override96 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {97 String originalContents = Contents.string(req);98 // There has to be a nicer way of doing this.99 Map<String, Object> contents = JSON.toType(originalContents, MAP_TYPE);100 Object using = contents.get("using");101 if (!(using instanceof String)) {102 return new HttpResponse()103 .setStatus(HTTP_BAD_REQUEST)104 .setContent(Contents.asJson(ImmutableMap.of(105 "value", ImmutableMap.of(106 "error", "invalid argument",107 "message", "Unable to determine element locating strategy",108 "stacktrace", ""))));109 }110 if (W3C_STRATEGIES.contains(using)) {111 // TODO: recreate the original request112 return toNode.execute(req);113 }114 Object value = contents.get("value");115 if (value == null) {116 return new HttpResponse()117 .setStatus(HTTP_BAD_REQUEST)118 .setContent(Contents.asJson(ImmutableMap.of(119 "value", ImmutableMap.of(120 "error", "invalid argument",121 "message", "Unable to determine element locator arguments",122 "stacktrace", ""))));123 }124 Function<Object, By> customLocator = extraLocators.get(using);125 if (customLocator == null) {126 return new HttpResponse()127 .setStatus(HTTP_BAD_REQUEST)128 .setContent(Contents.asJson(ImmutableMap.of(129 "value", ImmutableMap.of(130 "error", "invalid argument",131 "message", "Unable to determine element locating strategy for " + using,132 "stacktrace", ""))));133 }134 CommandExecutor executor = new NodeWrappingExecutor(toNode);135 RemoteWebDriver driver = new CustomWebDriver(136 executor,137 HttpSessionId.getSessionId(req.getUri())138 .orElseThrow(() -> new IllegalArgumentException("Cannot locate session ID from " + req.getUri())));139 SearchContext context = null;140 RemoteWebElement element;141 boolean findMultiple = false;142 UrlTemplate.Match match = FIND_ELEMENT.match(req.getUri());143 if (match != null) {144 element = new RemoteWebElement();145 element.setParent(driver);146 element.setId(match.getParameters().get("elementId"));147 context = driver;148 }149 match = FIND_ELEMENTS.match(req.getUri());150 if (match != null) {151 element = new RemoteWebElement();152 element.setParent(driver);153 element.setId(match.getParameters().get("elementId"));154 context = driver;155 findMultiple = true;156 }157 match = FIND_CHILD_ELEMENT.match(req.getUri());158 if (match != null) {159 element = new RemoteWebElement();160 element.setParent(driver);161 element.setId(match.getParameters().get("elementId"));162 context = element;163 }164 match = FIND_CHILD_ELEMENTS.match(req.getUri());165 if (match != null) {166 element = new RemoteWebElement();167 element.setParent(driver);168 element.setId(match.getParameters().get("elementId"));169 context = element;170 findMultiple = true;171 }172 if (context == null) {173 throw new IllegalStateException("Unable to determine locator context: " + req);174 }175 Object toReturn;176 By by = customLocator.apply(value);177 if (findMultiple) {178 toReturn = context.findElements(by);179 } else {180 toReturn = context.findElement(by);...

Full Screen

Full Screen

Source:OperationInDCMtree.java Github

copy

Full Screen

...13 Reporter.log("---------------------------DCMtree : start to import plan---------------------------");14 PageSource page = new PageSource();15 page.getXpathNameList( driver.getPageSource());16 String fileClickXpath = page.getXpathByName("File");17 org.openqa.selenium.remote.RemoteWebElement fileClickXpathButton = driver.findElementByXPath(fileClickXpath);18 fileClickXpathButton.click();19 Reporter.log("[Button Click] \'File\' Button click in DCMTree window");20 try {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;81 }82}...

Full Screen

Full Screen

Source:JsonToMobileElementConverter.java Github

copy

Full Screen

...20import com.google.common.collect.Maps;21import io.appium.java_client.HasSessionDetails;22import org.openqa.selenium.WebDriverException;23import org.openqa.selenium.remote.RemoteWebDriver;24import org.openqa.selenium.remote.RemoteWebElement;25import org.openqa.selenium.remote.internal.JsonToWebElementConverter;26import java.lang.reflect.Constructor;27import java.util.Collection;28import java.util.Map;29/**30 * Reconstitutes {@link org.openqa.selenium.WebElement}s from their JSON representation. Will recursively convert Lists31 * and Maps to catch nested references. All other values pass through the converter unchanged.32 */33public class JsonToMobileElementConverter extends JsonToWebElementConverter {34 protected final RemoteWebDriver driver;35 private final HasSessionDetails hasSessionDetails;36 /**37 * @param driver an instance of {@link org.openqa.selenium.remote.RemoteWebDriver} subclass38 * @param hasSessionDetails object that has session details39 */40 public JsonToMobileElementConverter(RemoteWebDriver driver, HasSessionDetails hasSessionDetails) {41 super(driver);42 this.driver = driver;43 this.hasSessionDetails = hasSessionDetails;44 }45 /**46 * This method converts a command result.47 *48 * @param result is the result of a command execution.49 * @return the result50 */51 public Object apply(Object result) {52 if (result instanceof Collection<?>) {53 Collection<?> results = (Collection<?>) result;54 return Lists.newArrayList(Iterables.transform(results, this));55 }56 if (result instanceof Map<?, ?>) {57 Map<?, ?> resultAsMap = (Map<?, ?>) result;58 if (resultAsMap.containsKey("ELEMENT")) {59 RemoteWebElement element = newMobileElement();60 element.setId(String.valueOf(resultAsMap.get("ELEMENT")));61 element.setFileDetector(driver.getFileDetector());62 return element;63 } else {64 return Maps.transformValues(resultAsMap, this);65 }66 }67 if (result instanceof Number) {68 if (result instanceof Float || result instanceof Double) {69 return ((Number) result).doubleValue();70 }71 return ((Number) result).longValue();72 }73 return result;74 }75 protected RemoteWebElement newMobileElement() {76 Class<? extends RemoteWebElement> target;77 target = getElementClass(hasSessionDetails);78 try {79 Constructor<? extends RemoteWebElement> constructor = target.getDeclaredConstructor();80 constructor.setAccessible(true);81 RemoteWebElement result = constructor.newInstance();82 result.setParent(driver);83 return result;84 } catch (Exception e) {85 throw new WebDriverException(e);86 }87 }88}...

Full Screen

Full Screen

Source:AdaptiveWebElement.java Github

copy

Full Screen

...16package org.auraframework.test.util;17import org.openqa.selenium.JavascriptExecutor;18import org.openqa.selenium.WebElement;19import org.openqa.selenium.remote.RemoteWebDriver;20import org.openqa.selenium.remote.RemoteWebElement;21import org.openqa.selenium.remote.internal.JsonToWebElementConverter;22/**23 * RemoteWebElement that implicitly tries to smooth WebDriver differences24 */25public class AdaptiveWebElement extends RemoteWebElement {26 public static class JsonConverter extends JsonToWebElementConverter {27 protected final RemoteWebDriver driver;28 public JsonConverter(RemoteWebDriver driver) {29 super(driver);30 this.driver = driver;31 }32 @Override33 protected RemoteWebElement newRemoteWebElement() {34 RemoteWebElement toReturn = new AdaptiveWebElement();35 toReturn.setParent(driver);36 return toReturn;37 }38 }39 public WebElement scrollIntoView() {40 try {41 getCoordinates().inViewPort();42 } catch (Exception ex) {43 // TODO ios-driver: NullPointerException at RemoteWebElement$1.inViewPort(RemoteWebElement.java:362)44 // Ignore Exception and try a different approach45 }46 ((JavascriptExecutor) getWrappedDriver()).executeScript("return arguments[0].scrollIntoView(true);", this);47 return this;48 }49 @Override50 public void click() {51 scrollIntoView();52 super.click();53 }54 @Override55 public void sendKeys(CharSequence... keysToSend) {56 scrollIntoView();57 super.sendKeys(keysToSend);...

Full Screen

Full Screen

Source:JsonToWebElementConverter.java Github

copy

Full Screen

...6import java.util.Collection;7import java.util.Map;8import org.openqa.selenium.remote.Dialect;9import org.openqa.selenium.remote.RemoteWebDriver;10import org.openqa.selenium.remote.RemoteWebElement;11public class JsonToWebElementConverter12 implements Function<Object, Object>13{14 private final RemoteWebDriver driver;15 16 public JsonToWebElementConverter(RemoteWebDriver driver)17 {18 this.driver = driver;19 }20 21 public Object apply(Object result) {22 if ((result instanceof Collection)) {23 Collection<?> results = (Collection)result;24 return Lists.newArrayList(Iterables.transform(results, this));25 }26 27 if ((result instanceof Map)) {28 Map<?, ?> resultAsMap = (Map)result;29 if (resultAsMap.containsKey(Dialect.OSS.getEncodedElementKey())) {30 RemoteWebElement element = newRemoteWebElement();31 element.setId(String.valueOf(resultAsMap.get(Dialect.OSS.getEncodedElementKey())));32 return element; }33 if (resultAsMap.containsKey(Dialect.W3C.getEncodedElementKey())) {34 RemoteWebElement element = newRemoteWebElement();35 element.setId(String.valueOf(resultAsMap.get(Dialect.W3C.getEncodedElementKey())));36 return element;37 }38 return Maps.transformValues(resultAsMap, this);39 }40 41 if ((result instanceof Number)) {42 if (((result instanceof Float)) || ((result instanceof Double))) {43 return Double.valueOf(((Number)result).doubleValue());44 }45 return Long.valueOf(((Number)result).longValue());46 }47 48 return result;49 }50 51 private RemoteWebElement newRemoteWebElement() {52 RemoteWebElement toReturn = new RemoteWebElement();53 toReturn.setParent(driver);54 toReturn.setFileDetector(driver.getFileDetector());55 return toReturn;56 }57}...

Full Screen

Full Screen

Source:DesktopElement.java Github

copy

Full Screen

1package winium.elements.desktop;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.remote.RemoteWebDriver;4import org.openqa.selenium.remote.RemoteWebElement;5import org.openqa.selenium.remote.Response;6import winium.elements.desktop.extensions.WebElementExtensions;7import java.util.Map;8public abstract class DesktopElement extends RemoteWebElement {9 private static RemoteWebDriver getRemoteWebDriver(WebElement element) {10 if (!(element instanceof RemoteWebElement))11 throw new ClassCastException("Specified cast is not valid. Please use RemoteWebElement as parameter.");12 RemoteWebElement remoteWebElement = (RemoteWebElement)element;13 return (RemoteWebDriver)remoteWebElement.getWrappedDriver();14 }15 protected DesktopElement(WebElement element) {16 this.setParent(getRemoteWebDriver(element));17 this.setId(WebElementExtensions.getId(element));18 }19 protected RemoteWebElement createRemoteWebElementFromResponse(Response response) {20 Object value = response.getValue();21 if (value instanceof RemoteWebElement){22 return (RemoteWebElement)value;23 }24 if (!(value instanceof Map<?, ?>)) {25 return null;26 }27 Map<?, ?> elementDictionary = (Map<?, ?>)value;28 RemoteWebElement result = new RemoteWebElement();29 result.setParent((RemoteWebDriver)this.getWrappedDriver());30 result.setId((String)elementDictionary.get("ELEMENT"));31 return result;32 }33}...

Full Screen

Full Screen

RemoteWebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebElement;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.firefox.FirefoxDriver;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.Platform;8import org.openqa.selenium.remote.BrowserType;9import org.openqa.selenium.remote.RemoteWebDriver;10import java.net.URL;11import java.net.MalformedURLException;12public class RemoteWebDriverExample {13 public static void main(String[] args) throws MalformedURLException {14 DesiredCapabilities capabilities = DesiredCapabilities.firefox();15 capabilities.setPlatform(Platform.MAC);16 capabilities.setBrowserName(BrowserType.FIREFOX);17 RemoteWebDriver driver = new RemoteWebDriver(url,capabilities);18 driver.quit();19 }20}21import org.openqa.selenium.remote.RemoteWebElement;22import org.openqa.selenium.WebElement;23import org.openqa.selenium.By;24import org.openqa.selenium.WebDriver;25import org.openqa.selenium.firefox.FirefoxDriver;

Full Screen

Full Screen

RemoteWebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebElement;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.firefox.FirefoxDriver;6import java.util.List;7import java.util.concurrent.TimeUnit;8import org.testng.Assert;9import org.testng.annotations.Test;10import org.testng.annotations.BeforeTest;11import org.testng.annotations.AfterTest;12public class TestNGExample {13 WebDriver driver;14 RemoteWebElement element;15 List<WebElement> list;16 public void beforeTest() {17 System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");18 driver = new FirefoxDriver();19 driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);20 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);21 driver.manage().window().maximize();22 }23 public void test() {24 Assert.assertEquals(driver.getTitle(), "Google");25 element = (RemoteWebElement) driver.findElement(By.name("q"));26 element.sendKeys("Selenium WebDriver");

Full Screen

Full Screen

RemoteWebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebElement;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.WebElement;6public class WebElementDemo {7public static void main(String[] args) {8WebDriver driver = new ChromeDriver();9((RemoteWebElement) element).sendKeys("Selenium");10((RemoteWebElement) element1).click();11driver.close();12}13}

Full Screen

Full Screen

RemoteWebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.chrome.ChromeOptions;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.RemoteWebElement;8import java.io.File;9import java.util.concurrent.TimeUnit;10public class ChromeDriverExample {11 public static void main(String[] args) {12 System.setProperty("webdriver.chrome.driver", "C:\\Users\\saurabh\\Downloads\\chromedriver_win32\\chromedriver.exe");13 ChromeOptions options = new ChromeOptions();14 options.addArguments("start-maximized");15 options.addArguments("disable-infobars");16 options.addArguments("--disable-extensions");17 options.addArguments("--disable-notifications");18 options.addArguments("--disable-popup-blocking");19 options.addArguments("--disable-translate");20 options.addArguments("--disable-geolocation");21 options.addArguments("--disable-gpu");22 options.addArguments("--disable-features=VizDisplayCompositor");23 options.addArguments("--disable-features=VizHitTestSurfaceLayer");24 options.addArguments("--disable-features=VizHitTestQuery");25 options.addArguments("--disable-features=VizDisplayCompositor");26 options.addArguments("--disable-features=VizHitTestSurfaceLayer");27 options.addArguments("--disable-features=VizHitTestQuery");28 options.addArguments("--disable-features=VizDisplayCompositor");29 options.addArguments("--disable-features=VizHitTestSurfaceLayer");30 options.addArguments("--disable-features=VizHitTestQuery");31 options.addArguments("--disable-features=VizDisplayCompositor");32 options.addArguments("--disable-features=VizHitTestSurfaceLayer");33 options.addArguments("--disable-features=VizHitTestQuery");34 options.addArguments("--disable-features=VizDisplayCompositor");35 options.addArguments("--disable-features=V

Full Screen

Full Screen

RemoteWebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebElement;2RemoteWebElement element = (RemoteWebElement) driver.findElement(By.id("element"));3String elementId = element.getId();4WebElement element = driver.findElement(By.id("element"));5String elementId = ((RemoteWebElement) element).getId();6WebElement element = driver.findElement(By.id("element"));7String elementId = ((RemoteWebElement) element).getId();8import org.openqa.selenium.remote.RemoteWebElement;9RemoteWebElement element = (RemoteWebElement) driver.findElement(By.id("element"));10String elementId = element.getId();11WebElement element = driver.findElement(By.id("element"));12String elementId = ((RemoteWebElement) element).getId();13import org.openqa.selenium.remote.RemoteWebElement;14RemoteWebElement element = (RemoteWebElement) driver.findElement(By.id("element"));15String elementId = element.getId();16WebElement element = driver.findElement(By.id("element"));17String elementId = ((RemoteWebElement) element).getId();18import org.openqa.selenium.remote.RemoteWebElement;19RemoteWebElement element = (RemoteWebElement) driver.findElement(By.id("element"));20String elementId = element.getId();21WebElement element = driver.findElement(By.id("element"));22String elementId = ((RemoteWebElement) element).getId();23import org.openqa.selenium.remote.RemoteWebElement;24RemoteWebElement element = (RemoteWebElement) driver.findElement(By.id("element"));25String elementId = element.getId();26WebElement element = driver.findElement(By.id("element"));27String elementId = ((RemoteWebElement) element).getId();28import org.openqa.selenium.remote.RemoteWebElement;29RemoteWebElement element = (RemoteWebElement) driver.findElement(By.id("element"));30String elementId = element.getId();31WebElement element = driver.findElement(By.id("element"));32String elementId = ((RemoteWebElement) element).getId();

Full Screen

Full Screen

RemoteWebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebElement;2import org.openqa.selenium.By;3import org.openqa.selenium.Keys;4import org.openqa.selenium.interactions.Actions;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.openqa.selenium.chrome.ChromeDriver;10import java.util.concurrent.TimeUnit;11import java.util.List;12import java.util.ArrayList;13import java.util.Arrays;14import java.util.HashMap;15import java.util.Map;16import java.util.Set;17import java.io.File;18import java.io.FileReader;19import java.io.BufferedReader;20import java.io.FileNotFoundException;21import java.io.IOException;22import java.net.MalformedURLException;23import java.net.URL;24import java.lang.InterruptedException;25import org.openqa.selenium.remote.DesiredCapabilities;26import org.openqa.selenium.remote.RemoteWebDriver;27import org.openqa.selenium.remote.RemoteWebElement;28import org.openqa.selenium.remote.SessionId;29import org.openqa.selenium.support.ui.WebDriverWait;30import org.openqa.selenium.support.ui.ExpectedConditions;31import org.openqa.selenium.JavascriptExecutor;32import org.openqa.selenium.support.ui.Select;

Full Screen

Full Screen
copy
11. Person person;22. person = new Person("Tom");33. changeName(person);44.55. //I didn't use Person person below as an argument to be nice66. static void changeName(Person anotherReferenceToTheSamePersonObject) {77. anotherReferenceToTheSamePersonObject.setName("Jerry");88. }9
Full Screen

Selenium 4 Tutorial:

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.

Chapters:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

...Most popular Stackoverflow questions on RemoteWebElement

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful