Advertisement
Guest User

Untitled

a guest
Mar 27th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. import java.awt.Toolkit;
  2. import java.awt.datatransfer.Clipboard;
  3. import java.awt.datatransfer.StringSelection;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.concurrent.TimeUnit;
  11.  
  12. import org.apache.poi.EncryptedDocumentException;
  13. import org.apache.poi.ss.usermodel.Cell;
  14. import org.apache.poi.ss.usermodel.Row;
  15. import org.apache.poi.ss.usermodel.Sheet;
  16. import org.apache.poi.ss.usermodel.Workbook;
  17. import org.apache.poi.ss.usermodel.WorkbookFactory;
  18. import org.jsoup.Jsoup;
  19. import org.junit.Assert;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.JavascriptExecutor;
  22. import org.openqa.selenium.Keys;
  23. import org.openqa.selenium.WebDriver;
  24. import org.openqa.selenium.WebElement;
  25. import org.openqa.selenium.chrome.ChromeDriver;
  26. import org.openqa.selenium.support.ui.ExpectedConditions;
  27. import org.openqa.selenium.support.ui.Select;
  28. import org.openqa.selenium.support.ui.WebDriverWait;
  29.  
  30. public class scopus {
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. public static void main(String[] args) throws EncryptedDocumentException, FileNotFoundException, IOException, InterruptedException {
  38. // TODO Auto-generated method stub
  39.  
  40. List<String> ISSN_List = new ArrayList<>();
  41. String saved_issn="";
  42. String enter_email = "30049683@westernsydney.edu.au";
  43.  
  44. File file = new File("Selenium.xlsx");
  45. Workbook wb = WorkbookFactory.create(new FileInputStream(file));
  46. Sheet sheet = wb.getSheetAt(0);
  47.  
  48. if (file.isFile() && file.exists()) {
  49. System.out.println("Selenium.xlsx open");
  50. }
  51. else {
  52. System.out.println("Selenium.xlsx either not exist"
  53. + " or can't open");
  54. }
  55.  
  56. //J = row Number
  57. for (int j=6; j< sheet.getLastRowNum(); j++) {
  58.  
  59.  
  60. Row row = sheet.getRow(j);
  61.  
  62. //gets Column number
  63. Cell issn_col = row.getCell(8);// Grabs all the Column ISSN
  64. Cell cummulative = row.getCell(2);
  65.  
  66. //Grabs the Value of the Cell
  67. String cellData= issn_col.getStringCellValue();
  68.  
  69. ISSN_List.add(cellData);
  70.  
  71.  
  72. }
  73.  
  74.  
  75.  
  76. saved_issn = ISSN_List.toString();
  77. saved_issn = saved_issn.substring(1, saved_issn.length() - 1);
  78.  
  79.  
  80. System.out.println(saved_issn);
  81. System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver.exe");
  82. String url ="https://www.scopus.com/customer/authenticate/loginfull.uri";
  83. String advanced_tab = "https://www.scopus.com/search/form.uri?display=advanced&origin=searchbasic&txGid=526775849ea4aa06b2c4852684f5e249";
  84. WebDriver driver = new ChromeDriver();
  85.  
  86.  
  87. driver.get(url);
  88.  
  89. try{
  90. Assert.assertEquals(url, driver.getCurrentUrl());
  91. System.out.println("Navigated to correct webpage");
  92. }
  93. catch(Throwable pageNavigationError){
  94. System.out.println("Didn't navigate to correct webpage");
  95. }
  96.  
  97.  
  98. //Login to the account
  99. WebElement username = driver.findElement(By.id("username"));
  100. username.sendKeys(enter_email);
  101. WebElement password = driver.findElement(By.id("password-input-password"));
  102. password.sendKeys("westernsydney");
  103. WebElement submit_password = driver.findElement(By.id("login_submit_btn"));
  104. submit_password.submit();
  105.  
  106. driver.get(advanced_tab);
  107.  
  108. try{
  109. Assert.assertEquals(advanced_tab, driver.getCurrentUrl());
  110. System.out.println("Navigated to correct webpage");
  111. }
  112. catch(Throwable pageNavigationError){
  113. System.out.println("Didn't navigate to correct webpage");
  114. }
  115.  
  116. saved_issn = "or ISSN(2161-2129), or ISSN(2150-7511), or ISSN(2210-6340), or ISSN(2210-6359), or ISSN(2077-7019)";
  117. setClipboardContents(saved_issn);
  118.  
  119.  
  120.  
  121. driver.findElement(By.id("searchfield")).sendKeys(Keys.CONTROL +"v");
  122. driver.findElement(By.id("searchfield")).sendKeys(Keys.RETURN);
  123.  
  124.  
  125.  
  126. //Checks the All the CheckBoxes
  127. if ( !driver.findElement(By.id("selectAllCheck")).isSelected() )
  128. {
  129. driver.findElement(By.id("selectAllCheck")).click();
  130. System.out.println("All select");
  131. }
  132.  
  133.  
  134.  
  135. //Clicks on View Citation Overview
  136. WebElement view_citation = driver.findElement(By.id("ctoDocResultLink"));
  137. view_citation.click();
  138.  
  139.  
  140. WebDriverWait wait = new WebDriverWait(driver, 20);
  141. wait.until(ExpectedConditions.elementToBeClickable(By.id("closeBigCTODialog")));
  142. setClipboardContents(enter_email);
  143. driver.findElement(By.id("emailCTO")).sendKeys(Keys.CONTROL +"v");
  144. driver.findElement(By.id("emailCTO")).sendKeys(Keys.RETURN);
  145.  
  146.  
  147. System.out.println("Hello");
  148. }
  149.  
  150.  
  151. public static void setClipboardContents(String text) {
  152. StringSelection stringSelection = new StringSelection( text );
  153. Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  154. clipboard.setContents(stringSelection, null);
  155. }
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement