Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Toolkit;
- import java.awt.datatransfer.Clipboard;
- import java.awt.datatransfer.StringSelection;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import org.apache.poi.EncryptedDocumentException;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.ss.usermodel.WorkbookFactory;
- import org.jsoup.Jsoup;
- import org.junit.Assert;
- import org.openqa.selenium.By;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.Keys;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.Select;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class scopus {
- public static void main(String[] args) throws EncryptedDocumentException, FileNotFoundException, IOException, InterruptedException {
- // TODO Auto-generated method stub
- List<String> ISSN_List = new ArrayList<>();
- List<Integer> checkpoint = new ArrayList<>();
- List<String> issn = new ArrayList<>();
- int cp =0;
- int begin = 0;
- String cellData;
- String search_year ="2012";
- String total_citation ="";
- String email_notification= " no email sent";
- String file_name = "";
- String saved_issn="";
- String enter_email = "30049683@westernsydney.edu.au";
- int cumulative_count = 10000;
- String FoR ="";
- File file = new File("Selenium.xlsx");
- Workbook wb = WorkbookFactory.create(new FileInputStream(file));
- Sheet sheet = wb.getSheetAt(0);
- FoR = wb.getSheetAt(0).getRow(6).getCell(6).toString();
- if (file.isFile() && file.exists()) {
- System.out.println("Selenium.xlsx open");
- }
- else {
- System.out.println("Selenium.xlsx either not exist"
- + " or can't open");
- }
- //J = row Number
- for (int j=6; j< sheet.getLastRowNum(); j++) {
- //Using 2 rows and ID's to compare for duplicate ID's
- Row row = sheet.getRow(j);
- Row row2 = sheet.getRow(j-1);
- Cell id = row.getCell(0);
- Cell id2= row2.getCell(0);
- //Grabs Cumulative Column
- Cell cumulative = row.getCell(3);
- //Grabs ISSN Column
- Cell issn_col = row.getCell(8);
- cp++;
- //Checks if the Cumulative count is equal to or greater than every 10k articles
- if(cumulative.getNumericCellValue()>= cumulative_count) {
- //Checks straddle ID's, if so create a checkpoint within the ArrayList
- if(id.getStringCellValue() != id2.getStringCellValue()) {
- cumulative_count = cumulative_count + 10000;
- checkpoint.add(cp);
- }
- }
- //Grabs the Value of the ISSN and adds it to the List
- cellData = issn_col.getStringCellValue();
- ISSN_List.add(cellData);
- }
- //Finalize The Checkpoint
- checkpoint.add(cp);
- for(int i=0;i<checkpoint.size();i++) {
- //Creates a temporary List array, from one checkpoint to another
- List <String> temp = ISSN_List.subList(begin, checkpoint.get(i));
- begin = checkpoint.get(i);
- //Stores into a string
- String temp_S = temp.toString();
- temp_S = temp_S.substring(1, temp_S.length() - 1);
- //Stores the checkpoint in one index position
- issn.add(temp_S);
- }
- for(int i = 0; i<checkpoint.size();i++) {
- saved_issn = issn.get(i).toString();
- saved_issn = saved_issn.substring(1, saved_issn.length());
- System.out.println("saved:"+saved_issn);
- System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver.exe");
- String url ="https://www.scopus.com/customer/authenticate/loginfull.uri";
- String advanced_tab = "https://www.scopus.com/search/form.uri?display=advanced&origin=searchbasic&txGid=526775849ea4aa06b2c4852684f5e249";
- WebDriver driver = new ChromeDriver();
- driver.get(url);
- try{
- Assert.assertEquals(url, driver.getCurrentUrl());
- System.out.println("Navigated to correct webpage");
- }
- catch(Throwable pageNavigationError){
- System.out.println("Didn't navigate to correct webpage");
- }
- //Login to the account
- WebElement username = driver.findElement(By.id("username"));
- username.sendKeys(enter_email);
- WebElement password = driver.findElement(By.id("password-input-password"));
- password.sendKeys("westernsydney");
- WebElement submit_password = driver.findElement(By.id("login_submit_btn"));
- submit_password.submit();
- //Grabs both Years for the found ISSNs
- for(int year =0; year<1; year++) {
- if(year ==0) saved_issn = saved_issn + " AND ( LIMIT-TO ( PUBYEAR , "+search_year+" ) ) AND ( LIMIT-TO ( DOCTYPE , \"ar\" ) OR LIMIT-TO ( DOCTYPE , \"re\" )";
- driver.get(advanced_tab);
- try{
- Assert.assertEquals(advanced_tab, driver.getCurrentUrl());
- System.out.println("Navigated to correct webpage");
- }
- catch(Throwable pageNavigationError){
- System.out.println("Didn't navigate to correct webpage");
- }
- setClipboardContents(saved_issn);
- driver.findElement(By.id("searchfield")).sendKeys(Keys.CONTROL +"v");
- driver.findElement(By.id("searchfield")).sendKeys(Keys.RETURN);
- //Checks the All the CheckBoxes
- if ( !driver.findElement(By.id("selectAllCheck")).isSelected() )
- {
- driver.findElement(By.id("selectAllCheck")).click();
- }
- //Clicks on View Citation Overview
- WebElement view_citation = driver.findElement(By.id("ctoDocResultLink"));
- view_citation.click();
- setClipboardContents(enter_email);
- WebDriverWait wait = new WebDriverWait(driver, 10);
- String no_of_articles = driver.findElement(By.className("resultsCount")).getText();
- try{
- wait.until(ExpectedConditions.elementToBeClickable(By.id("closeBigCTODialog")));
- driver.findElement(By.id("emailCTO")).sendKeys(Keys.CONTROL +"v");
- //Waits for email to be sent properly
- Thread.sleep(1000);
- driver.findElement(By.id("emailCTO")).sendKeys(Keys.RETURN);
- total_citation = "unkown";
- file_name= FoR +" "+ search_year+" "+ no_of_articles +".txt";
- }
- catch(Throwable pageNavigationError){
- //Grab FOR, ALL Publications, Citations and save it in.....
- total_citation = driver.findElement(By.id("grandtotal")).getText();
- file_name= FoR +" "+ search_year+" "+ no_of_articles +" "+email_notification+".txt";
- }
- PrintWriter writer = new PrintWriter(file_name, "UTF-8");
- writer.println("Year, "+ "No of articles,"+ " total_citations ");
- writer.println(search_year+", "+no_of_articles+", "+total_citation);
- writer.close();
- }
- driver.quit();
- }
- }
- public static void setClipboardContents(String text) {
- StringSelection stringSelection = new StringSelection( text );
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- clipboard.setContents(stringSelection, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement