SHOW:
|
|
- or go back to the newest paste.
1 | - | package control; |
1 | + | package control; |
2 | - | |
2 | + | |
3 | - | import java.util.ArrayList; |
3 | + | import java.util.ArrayList; |
4 | - | import java.util.Iterator; |
4 | + | import java.util.Iterator; |
5 | - | import java.util.List; |
5 | + | import java.util.List; |
6 | - | import java.util.concurrent.TimeUnit; |
6 | + | import java.util.concurrent.TimeUnit; |
7 | - | |
7 | + | |
8 | - | import org.openqa.selenium.By; |
8 | + | import org.openqa.selenium.By; |
9 | - | import org.openqa.selenium.JavascriptExecutor; |
9 | + | import org.openqa.selenium.JavascriptExecutor; |
10 | - | import org.openqa.selenium.Keys; |
10 | + | import org.openqa.selenium.Keys; |
11 | - | import org.openqa.selenium.WebDriver; |
11 | + | import org.openqa.selenium.WebDriver; |
12 | - | import org.openqa.selenium.WebElement; |
12 | + | import org.openqa.selenium.WebElement; |
13 | - | import org.openqa.selenium.firefox.FirefoxDriver; |
13 | + | import org.openqa.selenium.firefox.FirefoxDriver; |
14 | - | import org.openqa.selenium.support.ui.ExpectedCondition; |
14 | + | import org.openqa.selenium.support.ui.ExpectedCondition; |
15 | - | import org.openqa.selenium.support.ui.ExpectedConditions; |
15 | + | import org.openqa.selenium.support.ui.ExpectedConditions; |
16 | - | import org.openqa.selenium.support.ui.WebDriverWait; |
16 | + | import org.openqa.selenium.support.ui.WebDriverWait; |
17 | - | |
17 | + | |
18 | - | public class Bot { |
18 | + | public class Bot { |
19 | - | |
19 | + | |
20 | - | private final String user = "joshcooper"; |
20 | + | private final String user = "joshcooper"; |
21 | - | private final String pass = "qwertyq"; |
21 | + | private final String pass = "qwertyq"; |
22 | - | private final String URL = "https://www.vocabexpress.com/login/"; |
22 | + | private final String URL = "https://www.vocabexpress.com/login/"; |
23 | - | private final String learnURL = "https://www.vocabexpress.com/learnvocab/?cid=user-55641&qm=read&ipm=writ"; |
23 | + | private final String learnURL = "https://www.vocabexpress.com/learnvocab/?cid=user-55641&qm=read&ipm=writ"; |
24 | - | private final String userX = "//*[@id='main-body']/div/div/div[2]/form/p[1]/input"; |
24 | + | private final String userX = "//*[@id='main-body']/div/div/div[2]/form/p[1]/input"; |
25 | - | private final String passX= "//*[@id='main-body']/div/div/div[2]/form/p[2]/input"; |
25 | + | private final String passX= "//*[@id='main-body']/div/div/div[2]/form/p[2]/input"; |
26 | - | private final String loginX = "//*[@id='main-body']/div/div/div[2]/form/p[3]/input"; |
26 | + | private final String loginX = "//*[@id='main-body']/div/div/div[2]/form/p[3]/input"; |
27 | - | private final String tableX = "//*[@id='topiclist']/div[2]/div[2]"; |
27 | + | private final String tableX = "//*[@id='topiclist']/div[2]/div[2]"; |
28 | - | private final String wordTableX = "/html/body/div[4]/div[2]/div[1]/table/tbody[2]"; |
28 | + | private final String wordTableX = "/html/body/div[4]/div[2]/div[1]/table/tbody[2]"; |
29 | - | private final String wordAmountX = "/html/body/div[4]/div[2]/div[1]/table/tbody[1]/tr[4]/td[2]"; |
29 | + | private final String wordAmountX = "/html/body/div[4]/div[2]/div[1]/table/tbody[1]/tr[4]/td[2]"; |
30 | - | private final String testButtonX = "/html/body/div[4]/div[2]/div[1]/table/tbody[3]/tr[2]/td[2]/button"; |
30 | + | private final String testButtonX = "/html/body/div[4]/div[2]/div[1]/table/tbody[3]/tr[2]/td[2]/button"; |
31 | - | private final String okButtonX = "//*[@id='ms_ctrlbar']/input"; |
31 | + | private final String okButtonX = "//*[@id='ms_ctrlbar']/input"; |
32 | - | private final String startButtonX = "//*[@id='ipsb_start']"; |
32 | + | private final String startButtonX = "//*[@id='ipsb_start']"; |
33 | - | private final String translateTextX = "//*[@id='ip_ansbox']/div[1]/span[1]"; |
33 | + | private final String translateTextX = "//*[@id='ip_ansbox']/div[1]/span[1]"; |
34 | - | private final String entryBoxX = "//*[@id='ab_written']/input[1]"; |
34 | + | private final String entryBoxX = "//*[@id='ab_written']/input[1]"; |
35 | - | private final String submitButtonX = "//*[@id='ab_written']/input[2]"; |
35 | + | private final String submitButtonX = "//*[@id='ab_written']/input[2]"; |
36 | - | private final String finishButtonX = "//*[@id='ms_ctrlbar']/input"; |
36 | + | private final String finishButtonX = "//*[@id='ms_ctrlbar']/input"; |
37 | - | private final String closeButtonX = "/html/body/div[4]/div[1]/div[2]"; |
37 | + | private final String closeButtonX = "/html/body/div[4]/div[1]/div[2]"; |
38 | - | private final String table2X = "//*[@id='topiclist']/div[3]/div[2]"; |
38 | + | private final String table2X = "//*[@id='topiclist']/div[3]/div[2]"; |
39 | - | private final String table3X = "//*[@id='topiclist']/div[4]/div[2]"; |
39 | + | private final String table3X = "//*[@id='topiclist']/div[4]/div[2]"; |
40 | - | |
40 | + | |
41 | - | public Bot(){ |
41 | + | public Bot(){ |
42 | - | FirefoxDriver driver = new FirefoxDriver(); |
42 | + | FirefoxDriver driver = new FirefoxDriver(); |
43 | - | WebDriverWait driverWait = new WebDriverWait(driver, 5); |
43 | + | WebDriverWait driverWait = new WebDriverWait(driver, 5); |
44 | - | driver.get(URL); |
44 | + | driver.get(URL); |
45 | - | waitLoad(driver, driverWait); |
45 | + | waitLoad(driver, driverWait); |
46 | - | WebElement userField = driver.findElement(By.xpath(userX)); |
46 | + | WebElement userField = driver.findElement(By.xpath(userX)); |
47 | - | WebElement passField = driver.findElement(By.xpath(passX)); |
47 | + | WebElement passField = driver.findElement(By.xpath(passX)); |
48 | - | WebElement loginButton = driver.findElement(By.xpath(loginX)); |
48 | + | WebElement loginButton = driver.findElement(By.xpath(loginX)); |
49 | - | userField.sendKeys(user); |
49 | + | userField.sendKeys(user); |
50 | - | passField.sendKeys(pass); |
50 | + | passField.sendKeys(pass); |
51 | - | loginButton.click(); |
51 | + | loginButton.click(); |
52 | - | driver.get(learnURL); |
52 | + | driver.get(learnURL); |
53 | - | waitLoad(driver, driverWait); |
53 | + | waitLoad(driver, driverWait); |
54 | - | List<WebElement> allRows = driver.findElements(By.xpath(tableX)); |
54 | + | List<WebElement> allRows = driver.findElements(By.xpath(tableX)); |
55 | - | for(int aa = 0; aa < allRows.size(); aa++){ |
55 | + | for(int aa = 0; aa < allRows.size(); aa++){ |
56 | - | allRows = driver.findElements(By.xpath(tableX)); |
56 | + | allRows = driver.findElements(By.xpath(tableX)); |
57 | - | List<WebElement> allTasks = allRows.get(aa).findElements(By.className("bl_row")); |
57 | + | List<WebElement> allTasks = allRows.get(aa).findElements(By.className("bl_row")); |
58 | - | for(int ab = 0; ab < allTasks.size(); ab++){ |
58 | + | for(int ab = 0; ab < allTasks.size(); ab++){ |
59 | - | allRows = driver.findElements(By.xpath(tableX)); |
59 | + | allRows = driver.findElements(By.xpath(tableX)); |
60 | - | allTasks = allRows.get(aa).findElements(By.className("bl_row")); |
60 | + | allTasks = allRows.get(aa).findElements(By.className("bl_row")); |
61 | - | List<WebElement> taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
61 | + | List<WebElement> taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
62 | - | for(int ac = 0; ac < taskList.size(); ac++){ |
62 | + | for(int ac = 0; ac < taskList.size(); ac++){ |
63 | - | allRows = driver.findElements(By.xpath(tableX)); |
63 | + | allRows = driver.findElements(By.xpath(tableX)); |
64 | - | allTasks = allRows.get(aa).findElements(By.className("bl_row")); |
64 | + | allTasks = allRows.get(aa).findElements(By.className("bl_row")); |
65 | - | taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
65 | + | taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
66 | - | List<WebElement> completeAmount = taskList.get(ac).findElements(By.className("bstat_cm")); |
66 | + | List<WebElement> completeAmount = taskList.get(ac).findElements(By.className("bstat_cm")); |
67 | - | if(completeAmount.size() >= 1) continue; |
67 | + | if(completeAmount.size() >= 1) continue; |
68 | - | taskList.get(ac).click(); |
68 | + | taskList.get(ac).click(); |
69 | - | work(driver, driverWait); |
69 | + | work(driver, driverWait); |
70 | - | } |
70 | + | } |
71 | - | } |
71 | + | } |
72 | - | } |
72 | + | } |
73 | - | List<WebElement> allRows2 = driver.findElements(By.xpath(table2X)); |
73 | + | List<WebElement> allRows2 = driver.findElements(By.xpath(table2X)); |
74 | - | for(int aa = 0; aa < allRows2.size(); aa++){ |
74 | + | for(int aa = 0; aa < allRows2.size(); aa++){ |
75 | - | allRows2 = driver.findElements(By.xpath(table2X)); |
75 | + | allRows2 = driver.findElements(By.xpath(table2X)); |
76 | - | List<WebElement> tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
76 | + | List<WebElement> tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
77 | - | for(int ab = 0; ab < tabList.size(); ab++){ |
77 | + | for(int ab = 0; ab < tabList.size(); ab++){ |
78 | - | allRows2 = driver.findElements(By.xpath(table2X)); |
78 | + | allRows2 = driver.findElements(By.xpath(table2X)); |
79 | - | tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
79 | + | tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
80 | - | tabList.get(ab).click(); |
80 | + | tabList.get(ab).click(); |
81 | - | try { |
81 | + | try { |
82 | - | Thread.sleep(1000); |
82 | + | Thread.sleep(1000); |
83 | - | } catch (InterruptedException e) { |
83 | + | } catch (InterruptedException e) { |
84 | - | e.printStackTrace(); |
84 | + | e.printStackTrace(); |
85 | - | } |
85 | + | } |
86 | - | List<WebElement> allTasks = allRows2.get(aa).findElements(By.className("bl_row")); |
86 | + | List<WebElement> allTasks = allRows2.get(aa).findElements(By.className("bl_row")); |
87 | - | for(int ac = 0; ac < allTasks.size(); ac++){ |
87 | + | for(int ac = 0; ac < allTasks.size(); ac++){ |
88 | - | allRows2 = driver.findElements(By.xpath(table2X)); |
88 | + | allRows2 = driver.findElements(By.xpath(table2X)); |
89 | - | tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
89 | + | tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
90 | - | allTasks = allRows2.get(aa).findElements(By.className("bl_row")); |
90 | + | allTasks = allRows2.get(aa).findElements(By.className("bl_row")); |
91 | - | List<WebElement> taskList = allTasks.get(ac).findElements(By.className("bl_sqr")); |
91 | + | List<WebElement> taskList = allTasks.get(ac).findElements(By.className("bl_sqr")); |
92 | - | for(int ad = 0; ad < taskList.size(); ad++){ |
92 | + | for(int ad = 0; ad < taskList.size(); ad++){ |
93 | - | allRows2 = driver.findElements(By.xpath(table2X)); |
93 | + | allRows2 = driver.findElements(By.xpath(table2X)); |
94 | - | tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
94 | + | tabList = allRows2.get(aa).findElements(By.className("clicktop")); |
95 | - | allTasks = allRows2.get(aa).findElements(By.className("bl_row")); |
95 | + | allTasks = allRows2.get(aa).findElements(By.className("bl_row")); |
96 | - | taskList = allTasks.get(ac).findElements(By.className("bl_sqr")); |
96 | + | taskList = allTasks.get(ac).findElements(By.className("bl_sqr")); |
97 | - | List<WebElement> completeAmount = taskList.get(ad).findElements(By.className("bstat_cm")); |
97 | + | List<WebElement> completeAmount = taskList.get(ad).findElements(By.className("bstat_cm")); |
98 | - | if(completeAmount.size() >= 1 || !taskList.get(ad).isDisplayed()) continue; |
98 | + | if(completeAmount.size() >= 1 || !taskList.get(ad).isDisplayed()) continue; |
99 | - | taskList.get(ad).click(); |
99 | + | taskList.get(ad).click(); |
100 | - | work(driver, driverWait); |
100 | + | work(driver, driverWait); |
101 | - | } |
101 | + | } |
102 | - | } |
102 | + | } |
103 | - | tabList.get(ab).click(); |
103 | + | tabList.get(ab).click(); |
104 | - | try { |
104 | + | try { |
105 | - | Thread.sleep(1000); |
105 | + | Thread.sleep(1000); |
106 | - | } catch (InterruptedException e) { |
106 | + | } catch (InterruptedException e) { |
107 | - | e.printStackTrace(); |
107 | + | e.printStackTrace(); |
108 | - | } |
108 | + | } |
109 | - | } |
109 | + | } |
110 | - | } |
110 | + | } |
111 | - | List<WebElement> allRows3 = driver.findElements(By.xpath(table3X)); |
111 | + | List<WebElement> allRows3 = driver.findElements(By.xpath(table3X)); |
112 | - | for(int aa = 0; aa < allRows3.size(); aa++){ |
112 | + | for(int aa = 0; aa < allRows3.size(); aa++){ |
113 | - | allRows3 = driver.findElements(By.xpath(table3X)); |
113 | + | allRows3 = driver.findElements(By.xpath(table3X)); |
114 | - | List<WebElement> allTasks = allRows3.get(aa).findElements(By.className("bl_row")); |
114 | + | List<WebElement> allTasks = allRows3.get(aa).findElements(By.className("bl_row")); |
115 | - | for(int ab = 0; ab < allTasks.size(); ab++){ |
115 | + | for(int ab = 0; ab < allTasks.size(); ab++){ |
116 | - | allRows3 = driver.findElements(By.xpath(table3X)); |
116 | + | allRows3 = driver.findElements(By.xpath(table3X)); |
117 | - | allTasks = allRows3.get(aa).findElements(By.className("bl_row")); |
117 | + | allTasks = allRows3.get(aa).findElements(By.className("bl_row")); |
118 | - | List<WebElement> taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
118 | + | List<WebElement> taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
119 | - | for(int ac = 0; ac < taskList.size(); ac++){ |
119 | + | for(int ac = 0; ac < taskList.size(); ac++){ |
120 | - | allRows3 = driver.findElements(By.xpath(table3X)); |
120 | + | allRows3 = driver.findElements(By.xpath(table3X)); |
121 | - | allTasks = allRows3.get(aa).findElements(By.className("bl_row")); |
121 | + | allTasks = allRows3.get(aa).findElements(By.className("bl_row")); |
122 | - | taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
122 | + | taskList = allTasks.get(ab).findElements(By.className("bl_sqr")); |
123 | - | List<WebElement> completeAmount = taskList.get(ac).findElements(By.className("bstat_cm")); |
123 | + | List<WebElement> completeAmount = taskList.get(ac).findElements(By.className("bstat_cm")); |
124 | - | if(completeAmount.size() >= 1) continue; |
124 | + | if(completeAmount.size() >= 1) continue; |
125 | - | taskList.get(ac).click(); |
125 | + | taskList.get(ac).click(); |
126 | - | work(driver, driverWait); |
126 | + | work(driver, driverWait); |
127 | - | } |
127 | + | } |
128 | - | } |
128 | + | } |
129 | - | } |
129 | + | } |
130 | - | } |
130 | + | } |
131 | - | |
131 | + | |
132 | - | public void work(FirefoxDriver driver, WebDriverWait driverWait){ |
132 | + | public void work(FirefoxDriver driver, WebDriverWait driverWait){ |
133 | - | try { |
133 | + | try { |
134 | - | Thread.sleep(3000); |
134 | + | Thread.sleep(3000); |
135 | - | } catch (InterruptedException e) { |
135 | + | } catch (InterruptedException e) { |
136 | - | e.printStackTrace(); |
136 | + | e.printStackTrace(); |
137 | - | } |
137 | + | } |
138 | - | waitLoad(driver, driverWait); |
138 | + | waitLoad(driver, driverWait); |
139 | - | ArrayList<String> wordList = new ArrayList<String>(); |
139 | + | ArrayList<String> wordList = new ArrayList<String>(); |
140 | - | WebElement wordsTable = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(wordTableX))); |
140 | + | WebElement wordsTable = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(wordTableX))); |
141 | - | List<WebElement> wordsList = wordsTable.findElements(By.className("wpwrd")); |
141 | + | List<WebElement> wordsList = wordsTable.findElements(By.className("wpwrd")); |
142 | - | WebElement wordTotal = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(wordAmountX))); |
142 | + | WebElement wordTotal = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(wordAmountX))); |
143 | - | int total = Integer.parseInt(wordTotal.getText())*2; |
143 | + | int total = Integer.parseInt(wordTotal.getText())*2; |
144 | - | do{ |
144 | + | do{ |
145 | - | wordList.clear(); |
145 | + | wordList.clear(); |
146 | - | wordsList = wordsTable.findElements(By.className("wpwrd")); |
146 | + | wordsList = wordsTable.findElements(By.className("wpwrd")); |
147 | - | int n = 0; |
147 | + | int n = 0; |
148 | - | for(WebElement wf : wordsList){ |
148 | + | for(WebElement wf : wordsList){ |
149 | - | String s = wf.getText(); |
149 | + | String s = wf.getText(); |
150 | - | s = s.replaceAll("\\[.*?\\]", ""); |
150 | + | s = s.replaceAll("\\[.*?\\]", ""); |
151 | - | s = s.replaceAll("[\n\r]", ""); |
151 | + | s = s.replaceAll("[\n\r]", ""); |
152 | - | s = s.trim(); |
152 | + | s = s.trim(); |
153 | - | System.out.print(s); |
153 | + | System.out.print(s); |
154 | - | if(s.charAt(0) == ';'){ |
154 | + | if(s.charAt(0) == ';'){ |
155 | - | String old = wordList.get(n-1); |
155 | + | String old = wordList.get(n-1); |
156 | - | wordList.remove(n-1); |
156 | + | wordList.remove(n-1); |
157 | - | n--; |
157 | + | n--; |
158 | - | wordList.add(new String(old + s)); |
158 | + | wordList.add(new String(old + s)); |
159 | - | }else{ |
159 | + | }else{ |
160 | - | wordList.add(s); |
160 | + | wordList.add(s); |
161 | - | } |
161 | + | } |
162 | - | n++; |
162 | + | n++; |
163 | - | } |
163 | + | } |
164 | - | }while(wordList.size() != total); |
164 | + | }while(wordList.size() != total); |
165 | - | ArrayList<String[]> wordSet = new ArrayList<String[]>(); |
165 | + | ArrayList<String[]> wordSet = new ArrayList<String[]>(); |
166 | - | for(int n = 0; n < total/2; n++){ |
166 | + | for(int n = 0; n < total/2; n++){ |
167 | - | wordSet.add(new String[2]); |
167 | + | wordSet.add(new String[2]); |
168 | - | } |
168 | + | } |
169 | - | System.out.println(wordSet.size()); |
169 | + | System.out.println(wordSet.size()); |
170 | - | for(int c = 0; c < wordSet.size(); c++){ |
170 | + | for(int c = 0; c < wordSet.size(); c++){ |
171 | - | for(int n = c*2; n < c*2+2; n++){ |
171 | + | for(int n = c*2; n < c*2+2; n++){ |
172 | - | if(n % 2 == 0){ |
172 | + | if(n % 2 == 0){ |
173 | - | wordSet.get(c)[0] = wordList.get(n); |
173 | + | wordSet.get(c)[0] = wordList.get(n); |
174 | - | }else{ |
174 | + | }else{ |
175 | - | wordSet.get(c)[1] = wordList.get(n); |
175 | + | wordSet.get(c)[1] = wordList.get(n); |
176 | - | } |
176 | + | } |
177 | - | } |
177 | + | } |
178 | - | } |
178 | + | } |
179 | - | for(String[] word : wordSet){ |
179 | + | for(String[] word : wordSet){ |
180 | - | System.out.println("|" + word[0] + " " + word[1] + "|"); |
180 | + | System.out.println("|" + word[0] + " " + word[1] + "|"); |
181 | - | } |
181 | + | } |
182 | - | WebElement testButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(testButtonX))); |
182 | + | WebElement testButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(testButtonX))); |
183 | - | testButton.click(); |
183 | + | testButton.click(); |
184 | - | waitLoad(driver, driverWait); |
184 | + | waitLoad(driver, driverWait); |
185 | - | WebElement okButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(okButtonX))); |
185 | + | WebElement okButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(okButtonX))); |
186 | - | okButton.click(); |
186 | + | okButton.click(); |
187 | - | waitLoad(driver, driverWait); |
187 | + | waitLoad(driver, driverWait); |
188 | - | WebElement startButton = driver.findElement(By.xpath(startButtonX)); |
188 | + | WebElement startButton = driver.findElement(By.xpath(startButtonX)); |
189 | - | startButton.click(); |
189 | + | startButton.click(); |
190 | - | waitLoad(driver, driverWait); |
190 | + | waitLoad(driver, driverWait); |
191 | - | for(int w = 1; w <= total/2; w++){ |
191 | + | for(int w = 1; w <= total/2; w++){ |
192 | - | try { |
192 | + | try { |
193 | - | Thread.sleep(1500); |
193 | + | Thread.sleep(1500); |
194 | - | } catch (InterruptedException e) { |
194 | + | } catch (InterruptedException e) { |
195 | - | e.printStackTrace(); |
195 | + | e.printStackTrace(); |
196 | - | } |
196 | + | } |
197 | - | WebElement translateText = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(translateTextX))); |
197 | + | WebElement translateText = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(translateTextX))); |
198 | - | String text = translateText.getText(); |
198 | + | String text = translateText.getText(); |
199 | - | |
199 | + | |
200 | - | for(Iterator<String[]> iterator = wordSet.iterator(); iterator.hasNext();){ |
200 | + | for(Iterator<String[]> iterator = wordSet.iterator(); iterator.hasNext();){ |
201 | - | String[] s = iterator.next(); |
201 | + | String[] s = iterator.next(); |
202 | - | if(s[1].equals(text)){ |
202 | + | if(s[1].equals(text)){ |
203 | - | WebElement entryField = driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(entryBoxX))); |
203 | + | WebElement entryField = driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(entryBoxX))); |
204 | - | entryField.sendKeys(s[0]); |
204 | + | entryField.sendKeys(s[0]); |
205 | - | iterator.remove(); |
205 | + | iterator.remove(); |
206 | - | try { |
206 | + | try { |
207 | - | Thread.sleep(1000); |
207 | + | Thread.sleep(1000); |
208 | - | } catch (InterruptedException e) { |
208 | + | } catch (InterruptedException e) { |
209 | - | e.printStackTrace(); |
209 | + | e.printStackTrace(); |
210 | - | } |
210 | + | } |
211 | - | entryField.sendKeys(Keys.ENTER); |
211 | + | entryField.sendKeys(Keys.ENTER); |
212 | - | try { |
212 | + | try { |
213 | - | Thread.sleep(2500); |
213 | + | Thread.sleep(2500); |
214 | - | } catch (InterruptedException e) { |
214 | + | } catch (InterruptedException e) { |
215 | - | e.printStackTrace(); |
215 | + | e.printStackTrace(); |
216 | - | } |
216 | + | } |
217 | - | driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(submitButtonX))); |
217 | + | driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(submitButtonX))); |
218 | - | driver.switchTo().activeElement().click(); |
218 | + | driver.switchTo().activeElement().click(); |
219 | - | driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); |
219 | + | driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); |
220 | - | driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(entryBoxX))); |
220 | + | driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(entryBoxX))); |
221 | - | waitLoad(driver, driverWait); |
221 | + | waitLoad(driver, driverWait); |
222 | - | break; |
222 | + | break; |
223 | - | } |
223 | + | } |
224 | - | } |
224 | + | } |
225 | - | } |
225 | + | } |
226 | - | WebElement finishButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(finishButtonX))); |
226 | + | WebElement finishButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(finishButtonX))); |
227 | - | finishButton.click(); |
227 | + | finishButton.click(); |
228 | - | waitLoad(driver, driverWait); |
228 | + | waitLoad(driver, driverWait); |
229 | - | try { |
229 | + | try { |
230 | - | Thread.sleep(1500); |
230 | + | Thread.sleep(1500); |
231 | - | } catch (InterruptedException e) { |
231 | + | } catch (InterruptedException e) { |
232 | - | e.printStackTrace(); |
232 | + | e.printStackTrace(); |
233 | - | } |
233 | + | } |
234 | - | WebElement closeButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(closeButtonX))); |
234 | + | WebElement closeButton = driverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(closeButtonX))); |
235 | - | closeButton.click(); |
235 | + | closeButton.click(); |
236 | - | try { |
236 | + | try { |
237 | - | Thread.sleep(1000); |
237 | + | Thread.sleep(1000); |
238 | - | } catch (InterruptedException e) { |
238 | + | } catch (InterruptedException e) { |
239 | - | e.printStackTrace(); |
239 | + | e.printStackTrace(); |
240 | - | } |
240 | + | } |
241 | - | waitLoad(driver, driverWait); |
241 | + | waitLoad(driver, driverWait); |
242 | - | } |
242 | + | } |
243 | - | |
243 | + | |
244 | - | public static void main(String[] args){ |
244 | + | public static void main(String[] args){ |
245 | - | Bot bot = new Bot(); |
245 | + | Bot bot = new Bot(); |
246 | - | } |
246 | + | } |
247 | - | |
247 | + | |
248 | - | public void waitLoad(WebDriver driver, WebDriverWait driverWait){ |
248 | + | public void waitLoad(WebDriver driver, WebDriverWait driverWait){ |
249 | - | ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>(){ |
249 | + | ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>(){ |
250 | - | public Boolean apply(WebDriver driver) { |
250 | + | public Boolean apply(WebDriver driver) { |
251 | - | return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"); |
251 | + | return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"); |
252 | - | } |
252 | + | } |
253 | - | }; |
253 | + | }; |
254 | - | try { |
254 | + | try { |
255 | - | driverWait.until(expectation); |
255 | + | driverWait.until(expectation); |
256 | - | } catch(Throwable error) { |
256 | + | } catch(Throwable error) { |
257 | - | |
257 | + | |
258 | - | } |
258 | + | } |
259 | - | } |
259 | + | } |
260 | } |