Best Selenium code snippet using org.openqa.selenium.remote.RemoteWebElement.click
Source:pureElement.java
...192 }193 }194 195 // ************************************************************************************************************************ clear196 // WebElement [5] = public abstract void org.openqa.selenium.WebElement.click()197 // AndroidElement [38] = public void org.openqa.selenium.remote.RemoteWebElement.click()198 // IOSElement [37] = public void org.openqa.selenium.remote.RemoteWebElement.click()199 // MobileElement [37] = public void org.openqa.selenium.remote.RemoteWebElement.click()200 public void click() {201 this.refresh(); // Method to detect, update and centre the object on screen if existing.202 // this.centerOnScreen(); // Method to put object in center of the screen if partially or not visible203 this.pureElementMethodCall( "click" );204 }205 206 // ************************************************************************************************************************ clear207 // WebElement [6] = public abstract void org.openqa.selenium.WebElement.sendKeys(java.lang.CharSequence[])208 // AndroidElement [39] = public void org.openqa.selenium.remote.RemoteWebElement.sendKeys(java.lang.CharSequence[])209 // IOSElement [38] = public void org.openqa.selenium.remote.RemoteWebElement.sendKeys(java.lang.CharSequence[])210 // MobileElement [38] = public void org.openqa.selenium.remote.RemoteWebElement.sendKeys(java.lang.CharSequence[])211 public void sendKeys( String charSequence ) {212 this.refresh(); // Method to detect, update and centre the object on screen if existing.213 this.centerOnScreen(); // Method to put object in center of the screen if partially or not visible214 pureDriverDetails myDriver = pureDrivers.getCurrentDriverDetails();215 java.lang.CharSequence mySequency[] = new java.lang.CharSequence[ charSequence.length() ];216 for( int iLoop = 0; iLoop < charSequence.length(); iLoop++ ) {217 mySequency[ iLoop ] = charSequence.substring( iLoop, iLoop +1 );...
Source:BasicOperation.java
...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);...
Source:RemoteWebElementWrapper.java
...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);...
Source:NewRemoteWebElement.java
...25 26 private static final int CLICK_NUM = 10;27 private static final int MICRO_SLEEP = 200;28 private static final Pattern foundByPattern = Pattern.compile("\\[\\[.* -> (.*): (.*)\\]");29 private static boolean clickTimerOn = false;30 private static long totalClickTime;31 private static long startClickTime;32 private static FileDetector newRemoteElementFileDetector;33 private static final Semaphore configureFileDetectorSemaphore = new Semaphore(1);34 35 public NewRemoteWebElement(WebElement element) {36 RemoteWebElement remoteWebElement = (RemoteWebElement) element;37 id = remoteWebElement.getId();38 setParent((RemoteWebDriver) remoteWebElement.getWrappedDriver());39 configureFileDetector();40 41 // if possible take a locator and a term42 Matcher remoteWebElementInfo = foundByPattern.matcher(remoteWebElement.toString());43 if (remoteWebElementInfo.matches()) {44 setFoundBy(element, remoteWebElementInfo.group(1), remoteWebElementInfo.group(2));45 } else {46 BFLogger.logError("Incorrect FoundBy form WebElement " + remoteWebElement.toString());47 }48 }49 50 public static void setClickTimer() {51 clickTimerOn = true;52 totalClickTime = 0;53 }54 55 public static long dropClickTimer() {56 clickTimerOn = false;57 return totalClickTime;58 }59 60 /**61 * We are setting LocalFileDetector for interactions with a non-local grid, that is a Grid that is physically62 * on another host. Skipping that for local grid has some tiny performance advantage: file will not be sent over63 * network unnecessarily64 */65 private void configureFileDetector() {66 try {67 configureFileDetectorSemaphore.acquire();68 69 if (!Objects.isNull(newRemoteElementFileDetector)) {70 fileDetector = newRemoteElementFileDetector;71 } else {72 fileDetector = isRemoteGrid() ? new LocalFileDetector() : new UselessFileDetector();73 newRemoteElementFileDetector = fileDetector;74 BFLogger.logDebug("FileDetector for all NewRemoteWebElements will be set to " + fileDetector.getClass()75 .getCanonicalName());76 }77 78 configureFileDetectorSemaphore.release();79 } catch (InterruptedException e) {80 BFLogger.logError("FileDetector could not be set. The default will be used");81 }82 }83 84 private static boolean isRemoteGrid() {85 String gridHost = RuntimeParametersSelenium.SELENIUM_GRID.getValue()86 .trim();87 88 return getDriver().getClass()89 .getSimpleName()90 .equals("NewRemoteWebDriver") &&91 !gridHost.startsWith("http://127.0.0.1") &&92 !gridHost.startsWith("http://localhost");93 }94 95 /**96 * @deprecated As of release 1.0.0, replaced by {@link #findElementDynamic(By)()}97 */98 @Deprecated99 @Override100 public WebElement findElement(By by) throws BFElementNotFoundException {101 WebElement element = null;102 try {103 element = super.findElement(by);104 } catch (NoSuchElementException e) {105 throw new BFElementNotFoundException(by);106 }107 return new NewRemoteWebElement(element);108 }109 110 /**111 * @deprecated As of release 1.0.0, replaced by {@link #findElementDynamics(By)()}112 */113 @Deprecated114 @Override115 public List<WebElement> findElements(By by) {116 List<WebElement> elements = new ArrayList<WebElement>();117 for (WebElement element : super.findElements(by)) {118 elements.add(new NewRemoteWebElement(element));119 }120 return elements;121 }122 123 @Override124 public void click() throws StaleElementReferenceException {125 if (clickTimerOn) {126 startClickTime = System.currentTimeMillis();127 }128 try {129 super.click();130 } catch (ElementNotVisibleException e) {131 SelectorComponents selectorComponents = new SelectorComponents(toString());132 throw new BFComponentStateException(selectorComponents.getTerm(), "click", "not visible");133 } catch (StaleElementReferenceException e) {134 By selector = getSelector();135 if (selector == null) {136 calculateClickTime();137 throw e;138 }139 if (!click(selector, CLICK_NUM)) {140 calculateClickTime();141 throw e;142 }143 }144 calculateClickTime();145 }146 147 private void calculateClickTime() {148 if (clickTimerOn) {149 totalClickTime += System.currentTimeMillis() - startClickTime;150 }151 }152 153 private boolean click(By selector, int callNum) {154 try {155 TimeUtills.waitMiliseconds(MICRO_SLEEP);156 getWrappedDriver().findElement(selector)157 .click();158 return true;159 } catch (StaleElementReferenceException e) {160 if (callNum > 0) {161 return click(selector, callNum - 1);162 }163 }164 return false;165 }166 167 private By getSelector() {168 SelectorComponents selectorComponents = new SelectorComponents(toString());169 170 String term = selectorComponents.getTerm();171 if (term == null) {172 BFLogger.logError("Selector is not defined");173 return null;174 }175 ...
Source:TSRScroller.java
...23 * Automatically scrolls the element into view.24 *25 * <p>26 * Especially in the configuration page, the floating DIVs at the top and27 * the bottom of the pages can interfere with WebDriver trying to click28 * the elements underneath it.29 *30 * At least on Chrome (and possibly in other browsers), trying to interact31 * with an element when it's below another element causes the following error:32 *33 * <pre>34 * Tests run: 3, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 227.711 sec <<< FAILURE! - in plugins.AntPluginTest35 * autoInstallAnt(plugins.AntPluginTest) Time elapsed: 73.932 sec <<< ERROR!36 * org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (506, 967). Other element would receive the click: <div class="bottom-sticker-inner">...</div>37 * (Session info: chrome=34.0.1847.116)38 * (Driver info: chromedriver=2.10.267518,platform=Linux 3.13.0-24-generic x86_64) (WARNING: The server did not provide any stacktrace information)39 * Command duration or timeout: 61 milliseconds40 * Build info: version: '2.40.0', revision: '4c5c0568b004f67810ee41c459549aa4b09c651e', time: '2014-02-19 11:13:01'41 * System info: host: 'jglick-t520', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_55'42 * Session ID: 412a7b3ab0eb823da2cddd156e8d122c43 * Driver info: org.openqa.selenium.chrome.ChromeDriver44 * Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.3Xt0hp}, rotatable=false, locationContextEnabled=true, version=34.0.1847.116, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]45 * at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)46 * at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)47 * at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)48 * at java.lang.reflect.Constructor.newInstance(Constructor.java:526)49 * at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)50 * at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)51 * at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:573)52 * at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)53 * at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)54 * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)55 * at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)56 * at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)57 * at java.lang.reflect.Method.invoke(Method.java:606)58 * at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:331)59 * at com.sun.proxy.$Proxy33.click(Unknown Source)60 * at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:344)61 * at org.jenkinsci.test.acceptance.po.CapybaraPortingLayer.clickButton(CapybaraPortingLayer.java:66)62 * at org.jenkinsci.test.acceptance.po.JenkinsConfig.addTool(JenkinsConfig.java:35)63 * at org.jenkinsci.test.acceptance.plugins.ant.AntInstallation.install(AntInstallation.java:37)64 * at plugins.AntPluginTest.autoInstallAnt(AntPluginTest.java:76)65 * </pre>66 *67 * <p>68 * This work around simply tries to scroll the element into a view before we interact with this.69 * Originally developed in Ruby version of selenium-tests in <tt>lib/jenkins/capybara.rb</tt>.70 *71 * @author ogondza72 * @author Kohsuke Kawaguchi73 */74public class TSRScroller extends AbstractWebDriverEventListener {75 private final String scrollJs;...
Source:Scroller.java
...9 * Automatically scrolls the element into view.10 *11 * <p>12 * Especially in the configuration page, the floating DIVs at the top and13 * the bottom of the pages can interfere with WebDriver trying to click14 * the elements underneath it.15 *16 * At least on Chrome (and possibly in other browsers), trying to interact17 * with an element when it's below another element causes the following error:18 *19 * <pre>20 * Tests run: 3, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 227.711 sec <<< FAILURE! - in plugins.AntPluginTest21 * autoInstallAnt(plugins.AntPluginTest) Time elapsed: 73.932 sec <<< ERROR!22 * org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (506, 967). Other element would receive the click: <div class="bottom-sticker-inner">...</div>23 * (Session info: chrome=34.0.1847.116)24 * (Driver info: chromedriver=2.10.267518,platform=Linux 3.13.0-24-generic x86_64) (WARNING: The server did not provide any stacktrace information)25 * Command duration or timeout: 61 milliseconds26 * Build info: version: '2.40.0', revision: '4c5c0568b004f67810ee41c459549aa4b09c651e', time: '2014-02-19 11:13:01'27 * System info: host: 'jglick-t520', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_55'28 * Session ID: 412a7b3ab0eb823da2cddd156e8d122c29 * Driver info: org.openqa.selenium.chrome.ChromeDriver30 * Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.3Xt0hp}, rotatable=false, locationContextEnabled=true, version=34.0.1847.116, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]31 * at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)32 * at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)33 * at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)34 * at java.lang.reflect.Constructor.newInstance(Constructor.java:526)35 * at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)36 * at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)37 * at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:573)38 * at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)39 * at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)40 * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)41 * at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)42 * at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)43 * at java.lang.reflect.Method.invoke(Method.java:606)44 * at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:331)45 * at com.sun.proxy.$Proxy33.click(Unknown Source)46 * at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:344)47 * at org.jenkinsci.test.acceptance.po.CapybaraPortingLayer.clickButton(CapybaraPortingLayer.java:66)48 * at org.jenkinsci.test.acceptance.po.JenkinsConfig.addTool(JenkinsConfig.java:35)49 * at org.jenkinsci.test.acceptance.plugins.ant.AntInstallation.install(AntInstallation.java:37)50 * at plugins.AntPluginTest.autoInstallAnt(AntPluginTest.java:76)51 * </pre>52 *53 * <p>54 * This work around simply tries to scroll the element into a view before we interact with this.55 * Originally developed in Ruby version of selenium-tests in <tt>lib/jenkins/capybara.rb</tt>.56 *57 * @author ogondza58 * @author Kohsuke Kawaguchi59 */60public class Scroller extends AbstractWebDriverEventListener {61 private final String scrollJs;...
Source:OperationInDCMtree.java
...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}...
Source:AdaptiveWebElement.java
...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);58 }59}...
click
Using AI Code Generation
1package org.example;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6{7 public static void main( String[] args )8 {9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");10 WebDriver driver = new ChromeDriver();11 WebElement element = driver.findElement(By.name("q"));12 element.sendKeys("Selenium");13 element.submit();14 }15}16package org.example;17import org.openqa.selenium.By;18import org.openqa.selenium.WebDriver;19import org.openqa.selenium.WebElement;20import org.openqa.selenium.chrome.ChromeDriver;21{22 public static void main( String[] args )23 {24 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");25 WebDriver driver = new ChromeDriver();26 WebElement element = driver.findElement(By.name("q"));27 element.sendKeys("Selenium");28 element.submit();29 WebElement element1 = driver.findElement(By.name("btnK"));30 element1.click();31 }32}33How to Use the sendKeys() Method of the WebElement Interface to Enter Text in a Text Field?34How to Use the submit() Method of the WebElement Interface to Submit a Form?35How to Use the clear() Method of the WebElement Interface to Clear Text from a Text Field?36How to Use the isSelected() Method of the WebElement Interface to Check Whether a Checkbox is Selected or Not?37How to Use the isEnabled() Method of the WebElement Interface to Check Whether a Text Field is Enabled or Not?38How to Use the isDisplayed() Method of the WebElement Interface to Check Whether a Web Element is Displayed or Not?39How to Use the getAttribute() Method of the WebElement Interface to Get the Value of an Attribute of a Web
click
Using AI Code Generation
1import org.openqa.selenium.By;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.remote.RemoteWebElement;4import org.testng.annotations.Test;5public class ClickOnElement extends BaseTest {6 public void clickOnElement() {7 WebElement search = driver.findElement(By.name("q"));8 RemoteWebElement element = (RemoteWebElement) search;9 element.click();10 }11}
click
Using AI Code Generation
1import org.openqa.selenium.remote.RemoteWebElement2import org.openqa.selenium.By3import org.openqa.selenium.WebDriver4import org.openqa.selenium.WebElement5import org.openqa.selenium.chrome.ChromeDriver6import org.openqa.selenium.chrome.ChromeOptions7import org.openqa.selenium.support.ui.ExpectedConditions8import org.openqa.selenium.support.ui.WebDriverWait9import org.openqa.selenium.JavascriptExecutor10import org.openqa.selenium.interactions.Actions11import org.openqa.selenium.Keys12System.setProperty("webdriver.chrome.driver", "C:\\Users\\sourav\\Desktop\\chromedriver.exe")13ChromeOptions options = new ChromeOptions()14options.addArguments("--start-maximized")15options.addArguments("--disable-notifications")16options.addArguments("--disable-infobars")17WebDriver driver = new ChromeDriver(options)18WebElement searchTxt = driver.findElement(By.name("q"))19searchTxt.sendKeys("Selenium")20WebElement searchBtn = driver.findElement(By.name("btnK"))21searchBtn.click()22WebElement seleniumLink = driver.findElement(By.linkText("Selenium - Web Browser Automation"))23seleniumLink.click()24Thread.sleep(5000)25driver.quit()26driver.close()27driver.close()28driver.quit()
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!!