├── .idea
├── .gitignore
├── misc.xml
├── modules.xml
└── vcs.xml
├── Drivers
└── chromedriver.exe
├── LearningSeleniumBasics.iml
├── out
└── production
│ └── LearningSeleniumBasics
│ ├── Day3_Revision
│ └── XPathLocators
│ ├── Day4_Revision
│ ├── Day4_Notes
│ ├── DoubleClickAction.class
│ ├── FileUpload.class
│ ├── MouseHoverAction.class
│ └── RightClickAction.class
│ └── seleniumbasics
│ ├── 03MarchWedNesday
│ ├── LaunchApplication.class
│ └── LaunchApplication2.class
└── src
├── Day3_Revision
├── HandlingAuthPopUps.java
├── HandlingCheckboxes.java
├── HandlingLastTwoCheckboxes.java
├── HandlingMultipleCheckboxes.java
├── HandlingSelectiveCheckboxes.java
└── XPathLocators
├── Day4_Revision
├── Day4_Notes
├── DoubleClickAction.java
├── FileUpload.java
├── MouseHoverAction.java
└── RightClickAction.java
├── Day5_Revision
├── CustomCssSelectors.java
├── HandlingDropdown.java
├── HandlingDropdown2.java
└── HandlingDropdown3.java
├── Day6_Revision
├── CaptureScreenshot.java
├── HandlingDatePicker.java
├── HandlingDragDrop.java
├── HandlingExpliciteWait.java
├── HandlingIFrame.java
├── HandlingImpliciteWait.java
└── HandlingWindows.java
└── seleniumbasics
├── 03MarchWedNesday
├── BrowserClose.java
├── CapturePageSource.java
├── CaptureTitle.java
├── CaptureUrl.java
├── LaunchApplication.java
├── LaunchApplication2.java
└── PageRefresh.java
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Drivers/chromedriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SyntaxTechnologies/SeleniumBatch15ReviewSession/57a57412dfe4a166b9b2ad5036dacfebe438c037/Drivers/chromedriver.exe
--------------------------------------------------------------------------------
/LearningSeleniumBasics.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/Day3_Revision/XPathLocators:
--------------------------------------------------------------------------------
1 | XPath:
2 | Absolute Xpath [/html/body/div[1]/div[1]/div[1]/div/div/div/div[2]/div/div[1]/form/div[1]/div[1]/input]
3 | Relative Xpath [custom Xpath]
4 | 1. //tagName[@attributeName='value']
5 | //input[@id='userId'and @title='Email']
6 | //input[@id='userId'or @title='Email']
7 |
8 | 2. //tagName[text()='InnerText']
9 | 3. //tagName[contains(@attribute,'value')]
10 | //input[contains(@id,'userId')]
11 | 4. //tagName[contains(text(), 'innerText')]
12 |
13 |
14 | //input[@='iserId']
15 |
16 | =====================================================================
17 | XPath
18 | -Absolute [ Starts from html and /] -Explain
19 | -Relative [custom Xpath]
20 | //tagName[@attribute1='value1'] [ Use @ only before attributes]
21 | //tagName[text()='innerText']
22 | //tagName[contains(@attribute, 'attributeValue')]
23 | //tagName[contains(text(), 'innerText')]
24 |
25 | //tagName[@attribute1='value1' and @attribute2='value2']
26 | //tagName - //a, //input
27 | //input[@*='firstname']
28 | //tagName[@href]
29 |
30 | //tagName[@attribute1='value1' or @attribute2='value2']
31 | -> Attribute + text()
32 | -> Attribute + contains()
33 |
34 |
35 | //tagName[@attribute1='value1' and @attribute2='value2']
36 |
37 | starts-with()
38 | //tagName[starts-with(text(),'innerText')] - Amazon.in
39 | //a[@href] - 363 links
40 | ex: //a[starts-with(text(),'Amazon')] - 11 links
41 | https://classic.crmpro.com/
42 |
43 | //tagName[starts-with(@attribute,'value')]
44 | https://app.hubspot.com/login
45 | //input[starts-with(@type,'email')]
46 |
47 | ends-with() [ Earlier it was there but not now]
48 | Is XPath a Selenium property or a browser Property
49 | Is Xpath browser specific
50 | Show the same thing on FF
51 |
52 | Indexing Concept in Xpath
53 | https://naveenautomationlabs.com/opencart/index.php?route=account/login
54 | //input[@class='form-control']
55 | (//input[@class='form-control'])[1]
56 | (//input[@class='form-control'])[position()=1]
57 | https://naveenautomationlabs.com/opencart/index.php?route=account/register
58 | (//input[@class='form-control'])
59 |
60 | (//*[local-name()='svg']//*[name()='path' and @class='_34RNph'])[2]
61 |
62 | CSS Selectors: https://app.hubspot.com/login/
63 | #id [#username]
64 | tagName#id
65 | input#username [FASTER]
66 |
67 | .class [.private-form__input-wrapper]
68 | tagName.className [div.private-form__input-wrapper]
69 |
70 | .c1.c2.c3.....cn [.form-control.private-form__control.login-email]
71 | tagName.c1.c2.c3..............cn [input.form-control.private-form__control.login-email]
72 |
73 | =====================================================================================================================
74 | // ChromeOptions options = new ChromeOptions();
75 | // options.addArguments("--remote-allow-origins=*");
76 | // WebDriver driver = new EdgeDriver(options);
77 | =====================================================================================================================
78 | Checkboxes:
79 | https://itera-qa.azurewebsites.net/home/automation
80 |
81 | //input[@type='checkbox' and contains(@id,'day')]
82 | //label/input[@type='checkbox']
83 |
84 | ======================================================================================================================
85 | Alerts [https://the-internet.herokuapp.com/]
86 | https://the-internet.herokuapp.com/javascript_alerts
87 | JS Alert: alert/prompt/confirm [JS pop ups cannot have locator path]
88 | NOTE: JS POP up cant be multiple and will have at the max one pop up, also JS pop up will come when you perform some action on WebPage
89 | https://mail.rediff.com/cgi-bin/login.cgi[HW]
90 |
91 | but BASIC AUTH will come on the page loading itself
92 | https://the-internet.herokuapp.com/basic_auth
93 |
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/Day4_Revision/Day4_Notes:
--------------------------------------------------------------------------------
1 | // tagName[@attributeName='attributeValue']
2 | // tagName[text()='innerText']
3 | // tagName[contains(@attributeName, 'attributeValue')]
4 | // tagName[contains(text(), 'innerText')]
5 |
6 | https://www.facebook.com/
7 | // attributes + text [//button[text()='Log in' and @name='login']
8 | // text() + contains() [//button[text()='Log in' and contains(@name,'log')]]
9 | // and, or
10 |
11 | https://www.orangehrm.com/hris-hr-software-demo/
12 | // indexing [(//input[@required='required'])[position()=1]
13 | (//input[@required='required'])[1]
14 | last webElement->(//input[@required='required'])[last()]
15 | second last -> (//input[@required='required'])[last()-n]
16 |
17 |
18 |
19 |
[w.r.t button this is preceding-sibling]
20 |
[w.r.t label this is following-sibling]
21 |
22 |
23 |
24 | div-label [pc r'ship]
25 | div-button[pc r'ship]
26 | label-button [siblings]
27 |
28 | https://app.hubspot.com/login/
29 | traversing to the parent tag
30 | //input[@id='username']/../../../../../../../../../../..
31 | //input[@id='username']/parent::div/parent::div/parent::div/parent::div/parent::form
32 |
33 | //tagName[@attributeName='value']/..
34 | //tagName[@attributeName='value']/parent::ParentTagName
35 |
36 | // following-sibling
37 | https://naveenautomationlabs.com/opencart/index.php?route=account/login
38 | //label[text()='E-Mail Address']/following-sibling::input
39 |
40 | //input[@id='input-email']/preceding-sibling::label
41 |
42 |
43 | https://app.hubspot.com/login/
44 | //i18n-string[text()='Email address']/parent::span/parent::label/parent::div/following-sibling::div/input
45 |
46 | Ancestors:
47 | //i18n-string[text()='Email address']/ancestor::label/parent::div/following-sibling::div/input
48 |
49 | =======================================
50 | Xpath Axes:
51 | parent
52 | following-sibling
53 | preceding-sibling
54 | ancestor
55 | ======================================
56 |
57 | // https://www.espncricinfo.com/series/australia-in-india-2022-23-1348637/india-vs-australia-2nd-odi-1348657/full-scorecard
58 | // Create a generic Xpath where by changing the name of player we should be able to know the runs scored by him
59 | //span[text()='Virat Kohli']/parent::span/parent::a/parent::td/following-sibling::td/strong
60 |
61 | // Using ancestors
62 | //span[text()='Virat Kohli']/ancestor::td/following-sibling::td/strong
63 |
64 |
65 |
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/Day4_Revision/DoubleClickAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SyntaxTechnologies/SeleniumBatch15ReviewSession/57a57412dfe4a166b9b2ad5036dacfebe438c037/out/production/LearningSeleniumBasics/Day4_Revision/DoubleClickAction.class
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/Day4_Revision/FileUpload.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SyntaxTechnologies/SeleniumBatch15ReviewSession/57a57412dfe4a166b9b2ad5036dacfebe438c037/out/production/LearningSeleniumBasics/Day4_Revision/FileUpload.class
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/Day4_Revision/MouseHoverAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SyntaxTechnologies/SeleniumBatch15ReviewSession/57a57412dfe4a166b9b2ad5036dacfebe438c037/out/production/LearningSeleniumBasics/Day4_Revision/MouseHoverAction.class
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/Day4_Revision/RightClickAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SyntaxTechnologies/SeleniumBatch15ReviewSession/57a57412dfe4a166b9b2ad5036dacfebe438c037/out/production/LearningSeleniumBasics/Day4_Revision/RightClickAction.class
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/seleniumbasics/03MarchWedNesday:
--------------------------------------------------------------------------------
1 | 1- Xpath [ Relative/Absolute]
2 | //tagName[@attributeName='value']
3 | //tagName[text()='innerText']
4 | //tagName[contains(@AttributeName/text(), 'attributeValue/InnerText')]
5 |
6 | Talk about absolute path and Relative path with more examples
7 |
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/seleniumbasics/LaunchApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SyntaxTechnologies/SeleniumBatch15ReviewSession/57a57412dfe4a166b9b2ad5036dacfebe438c037/out/production/LearningSeleniumBasics/seleniumbasics/LaunchApplication.class
--------------------------------------------------------------------------------
/out/production/LearningSeleniumBasics/seleniumbasics/LaunchApplication2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SyntaxTechnologies/SeleniumBatch15ReviewSession/57a57412dfe4a166b9b2ad5036dacfebe438c037/out/production/LearningSeleniumBasics/seleniumbasics/LaunchApplication2.class
--------------------------------------------------------------------------------
/src/Day3_Revision/HandlingAuthPopUps.java:
--------------------------------------------------------------------------------
1 | package Day3_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.chrome.ChromeOptions;
7 |
8 | public class HandlingAuthPopUps {
9 |
10 | public static void main(String[] args) {
11 |
12 | ChromeOptions options = new ChromeOptions();
13 | options.addArguments("--remote-allow-origins=*");
14 | WebDriver driver = new ChromeDriver(options);
15 | driver.get("https://admin:admin@the-internet.herokuapp.com/basic_auth");
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Day3_Revision/HandlingCheckboxes.java:
--------------------------------------------------------------------------------
1 | package Day3_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.chrome.ChromeOptions;
7 |
8 | public class HandlingCheckboxes {
9 |
10 | public static void main(String[] args) {
11 |
12 | ChromeOptions options = new ChromeOptions();
13 | options.addArguments("--remote-allow-origins=*");
14 | WebDriver driver = new ChromeDriver(options);
15 |
16 | driver.get("https://itera-qa.azurewebsites.net/home/automation");
17 | driver.findElement(By.xpath("//input[@id='monday']")).click();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Day3_Revision/HandlingLastTwoCheckboxes.java:
--------------------------------------------------------------------------------
1 | package Day3_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 |
9 | import java.util.List;
10 |
11 | public class HandlingLastTwoCheckboxes {
12 |
13 | public static void main(String[] args) {
14 |
15 | ChromeOptions options = new ChromeOptions();
16 | options.addArguments("--remote-allow-origins=*");
17 | WebDriver driver = new ChromeDriver(options);
18 |
19 | driver.get("https://itera-qa.azurewebsites.net/home/automation");
20 | //driver.findElement(By.xpath("//input[@id='monday']")).click();
21 | List days =driver.findElements(By.xpath("//input[@type='checkbox' and contains(@id,'day')]"));
22 | for(int i=5; i<=days.size(); i++)
23 | {
24 | days.get(i).click();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Day3_Revision/HandlingMultipleCheckboxes.java:
--------------------------------------------------------------------------------
1 | package Day3_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 |
9 | import java.util.List;
10 |
11 | public class HandlingMultipleCheckboxes {
12 |
13 | public static void main(String[] args) {
14 |
15 | ChromeOptions options = new ChromeOptions();
16 | options.addArguments("--remote-allow-origins=*");
17 | WebDriver driver = new ChromeDriver(options);
18 |
19 | driver.get("https://itera-qa.azurewebsites.net/home/automation");
20 | List< WebElement> days =driver.findElements(By.xpath("//input[@type='checkbox' and contains(@id,'day')]"));
21 | // for(WebElement day:days)
22 | // {
23 | // day.click();
24 | // }
25 |
26 | for(int i=0; i<=days.size(); i++)
27 | {
28 | days.get(i).click();
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Day3_Revision/HandlingSelectiveCheckboxes.java:
--------------------------------------------------------------------------------
1 | package Day3_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 |
9 | import java.util.List;
10 |
11 | public class HandlingSelectiveCheckboxes {
12 |
13 | public static void main(String[] args) {
14 |
15 | ChromeOptions options = new ChromeOptions();
16 | options.addArguments("--remote-allow-origins=*");
17 | WebDriver driver = new ChromeDriver(options);
18 |
19 | driver.get("https://itera-qa.azurewebsites.net/home/automation");
20 | List days =driver.findElements(By.xpath("//input[@type='checkbox' and contains(@id,'day')]"));
21 | for (WebElement day : days)
22 | {
23 | if(day.getAttribute("id").equalsIgnoreCase("tuesday")||day.getAttribute("id").equalsIgnoreCase("thursday")||day.getAttribute("id").equalsIgnoreCase("saturday"))
24 | {
25 | day.click();
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Day3_Revision/XPathLocators:
--------------------------------------------------------------------------------
1 | XPath:
2 | Absolute Xpath [/html/body/div[1]/div[1]/div[1]/div/div/div/div[2]/div/div[1]/form/div[1]/div[1]/input]
3 | Relative Xpath [custom Xpath]
4 | 1. //tagName[@attributeName='value']
5 | //input[@id='userId'and @title='Email']
6 | //input[@id='userId'or @title='Email']
7 |
8 | 2. //tagName[text()='InnerText']
9 | 3. //tagName[contains(@attribute,'value')]
10 | //input[contains(@id,'userId')]
11 | 4. //tagName[contains(text(), 'innerText')]
12 |
13 |
14 | //input[@='iserId']
15 |
16 | =====================================================================
17 | XPath
18 | -Absolute [ Starts from html and /] -Explain
19 | -Relative [custom Xpath]
20 | //tagName[@attribute1='value1'] [ Use @ only before attributes]
21 | //tagName[text()='innerText']
22 | //tagName[contains(@attribute, 'attributeValue')]
23 | //tagName[contains(text(), 'innerText')]
24 |
25 | //tagName[@attribute1='value1' and @attribute2='value2']
26 | //tagName - //a, //input
27 | //input[@*='firstname']
28 | //tagName[@href]
29 |
30 | //tagName[@attribute1='value1' or @attribute2='value2']
31 | -> Attribute + text()
32 | -> Attribute + contains()
33 |
34 |
35 | //tagName[@attribute1='value1' and @attribute2='value2']
36 |
37 | starts-with()
38 | //tagName[starts-with(text(),'innerText')] - Amazon.in
39 | //a[@href] - 363 links
40 | ex: //a[starts-with(text(),'Amazon')] - 11 links
41 | https://classic.crmpro.com/
42 |
43 | //tagName[starts-with(@attribute,'value')]
44 | https://app.hubspot.com/login
45 | //input[starts-with(@type,'email')]
46 |
47 | ends-with() [ Earlier it was there but not now]
48 | Is XPath a Selenium property or a browser Property
49 | Is Xpath browser specific
50 | Show the same thing on FF
51 |
52 | Indexing Concept in Xpath
53 | https://naveenautomationlabs.com/opencart/index.php?route=account/login
54 | //input[@class='form-control']
55 | (//input[@class='form-control'])[1]
56 | (//input[@class='form-control'])[position()=1]
57 | https://naveenautomationlabs.com/opencart/index.php?route=account/register
58 | (//input[@class='form-control'])
59 |
60 | (//*[local-name()='svg']//*[name()='path' and @class='_34RNph'])[2]
61 |
62 | CSS Selectors: https://app.hubspot.com/login/
63 | #id [#username]
64 | tagName#id
65 | input#username [FASTER]
66 |
67 | .class [.private-form__input-wrapper]
68 | tagName.className [div.private-form__input-wrapper]
69 |
70 | .c1.c2.c3.....cn [.form-control.private-form__control.login-email]
71 | tagName.c1.c2.c3..............cn [input.form-control.private-form__control.login-email]
72 |
73 | =====================================================================================================================
74 | // ChromeOptions options = new ChromeOptions();
75 | // options.addArguments("--remote-allow-origins=*");
76 | // WebDriver driver = new EdgeDriver(options);
77 | =====================================================================================================================
78 | Checkboxes:
79 | https://itera-qa.azurewebsites.net/home/automation
80 |
81 | //input[@type='checkbox' and contains(@id,'day')]
82 | //label/input[@type='checkbox']
83 |
84 | ======================================================================================================================
85 | Alerts [https://the-internet.herokuapp.com/]
86 | https://the-internet.herokuapp.com/javascript_alerts
87 | JS Alert: alert/prompt/confirm [JS pop ups cannot have locator path]
88 | NOTE: JS POP up cant be multiple and will have at the max one pop up, also JS pop up will come when you perform some action on WebPage
89 | https://mail.rediff.com/cgi-bin/login.cgi[HW]
90 |
91 | but BASIC AUTH will come on the page loading itself
92 | https://the-internet.herokuapp.com/basic_auth
93 |
--------------------------------------------------------------------------------
/src/Day4_Revision/Day4_Notes:
--------------------------------------------------------------------------------
1 | // tagName[@attributeName='attributeValue']
2 | // tagName[text()='innerText']
3 | // tagName[contains(@attributeName, 'attributeValue')]
4 | // tagName[contains(text(), 'innerText')]
5 |
6 | https://www.facebook.com/
7 | // attributes + text [//button[text()='Log in' and @name='login']
8 | // text() + contains() [//button[text()='Log in' and contains(@name,'log')]]
9 | // and, or
10 |
11 | https://www.orangehrm.com/hris-hr-software-demo/
12 | // indexing [(//input[@required='required'])[position()=1]
13 | (//input[@required='required'])[1]
14 | last webElement->(//input[@required='required'])[last()]
15 | second last -> (//input[@required='required'])[last()-n]
16 |
17 |
18 |
19 |
[w.r.t button this is preceding-sibling]
20 |
[w.r.t label this is following-sibling]
21 |
22 |
23 |
24 | div-label [pc r'ship]
25 | div-button[pc r'ship]
26 | label-button [siblings]
27 |
28 | https://app.hubspot.com/login/
29 | traversing to the parent tag
30 | //input[@id='username']/../../../../../../../../../../..
31 | //input[@id='username']/parent::div/parent::div/parent::div/parent::div/parent::form
32 |
33 | //tagName[@attributeName='value']/..
34 | //tagName[@attributeName='value']/parent::ParentTagName
35 |
36 | // following-sibling
37 | https://naveenautomationlabs.com/opencart/index.php?route=account/login
38 | //label[text()='E-Mail Address']/following-sibling::input
39 |
40 | //input[@id='input-email']/preceding-sibling::label
41 |
42 |
43 | https://app.hubspot.com/login/
44 | //i18n-string[text()='Email address']/parent::span/parent::label/parent::div/following-sibling::div/input
45 |
46 | Ancestors:
47 | //i18n-string[text()='Email address']/ancestor::label/parent::div/following-sibling::div/input
48 |
49 | =======================================
50 | Xpath Axes:
51 | parent
52 | following-sibling
53 | preceding-sibling
54 | ancestor
55 | ======================================
56 |
57 | // https://www.espncricinfo.com/series/australia-in-india-2022-23-1348637/india-vs-australia-2nd-odi-1348657/full-scorecard
58 | // Create a generic Xpath where by changing the name of player we should be able to know the runs scored by him
59 | //span[text()='Virat Kohli']/parent::span/parent::a/parent::td/following-sibling::td/strong
60 |
61 | // Using ancestors
62 | //span[text()='Virat Kohli']/ancestor::td/following-sibling::td/strong
63 |
64 |
65 |
--------------------------------------------------------------------------------
/src/Day4_Revision/DoubleClickAction.java:
--------------------------------------------------------------------------------
1 | package Day4_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.interactions.Actions;
9 |
10 | public class DoubleClickAction {
11 |
12 | public static void main(String[] args) {
13 | ChromeOptions options = new ChromeOptions();
14 | options.addArguments("--remote-allow-origins=*");
15 | WebDriver driver = new ChromeDriver(options);
16 | driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_ondblclick3");
17 | driver.switchTo().frame("iframeResult");
18 | WebElement doubleClickButton= driver.findElement(By.xpath("//button[text()='Copy Text']"));
19 | Actions act = new Actions(driver);
20 | act.doubleClick(doubleClickButton).perform();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Day4_Revision/FileUpload.java:
--------------------------------------------------------------------------------
1 | package Day4_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.chrome.ChromeOptions;
7 |
8 | public class FileUpload {
9 |
10 | public static void main(String[] args) throws InterruptedException {
11 |
12 | ChromeOptions options = new ChromeOptions();
13 | options.addArguments("--remote-allow-origins=*");
14 | WebDriver driver = new ChromeDriver(options);
15 | driver.get("http://nervgh.github.io/pages/angular-file-upload/examples/simple/");
16 | Thread.sleep(2000);
17 | driver.findElement(By.xpath("//input[@multiple]")).sendKeys("C:\\Users\\91886\\Downloads\\MyTextDetails.txt");
18 |
19 | // Note: This will work only for those file upload button for which the tag name is input and type is file
20 | // sendKeys use
21 | // 1. entering values in the text boxes
22 | // 2. uploading the file
23 | // 3. for performing the keyboard interactions
24 |
25 | // to scroll, Drag and drop, double, hover
26 | // Mouse Actions
27 | // How to perform right click
28 | // How to perform double click
29 | // How to perform drag and drop
30 | // How to perform Mouse hover
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Day4_Revision/MouseHoverAction.java:
--------------------------------------------------------------------------------
1 | package Day4_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.interactions.Actions;
9 |
10 | public class MouseHoverAction {
11 |
12 | public static void main(String[] args) {
13 | ChromeOptions options = new ChromeOptions();
14 | options.addArguments("--remote-allow-origins=*");
15 | WebDriver driver = new ChromeDriver(options);
16 | driver.get("https://demo.opencart.com/");
17 | WebElement menuItem =driver.findElement(By.xpath("//a[text()='Components']"));
18 |
19 | Actions act = new Actions(driver);
20 | act.moveToElement(menuItem).perform();
21 | WebElement subMenuItem= driver.findElement(By.xpath("//a[contains(text(), 'Monitors')]"));
22 | act.moveToElement(subMenuItem).click().perform();
23 |
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Day4_Revision/RightClickAction.java:
--------------------------------------------------------------------------------
1 | package Day4_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.interactions.Actions;
9 |
10 | public class RightClickAction {
11 |
12 | public static void main(String[] args) {
13 | ChromeOptions options = new ChromeOptions();
14 | options.addArguments("--remote-allow-origins=*");
15 | WebDriver driver = new ChromeDriver(options);
16 | driver.get("https://swisnl.github.io/jQuery-contextMenu/demo.html");
17 | WebElement rightClickButton = driver.findElement(By.xpath("//span[text()='right click me']"));
18 | Actions act = new Actions(driver);
19 | act.contextClick(rightClickButton).perform();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Day5_Revision/CustomCssSelectors.java:
--------------------------------------------------------------------------------
1 | package Day5_Revision;
2 |
3 | public class CustomCssSelectors {
4 |
5 | // ==============================ID=================================
6 | // https://naveenautomationlabs.com/opencart/index.php?route=account/register
7 | //1. Id in CSS ==> #id
8 | // #input-firstname
9 | //2. tagName#id
10 | // input#input-firstname
11 |
12 | //================================Class==================================
13 | // 1.Class in CSS => .classValue
14 | // .form-control
15 | // 2. tagName.classValue
16 |
17 | //=============================Multiple Classes===================================
18 | // https://app.hubspot.com/login
19 | // 1. .c1.c2.c3.....cn
20 | // .form-control.private-form__control.login-email
21 | //2.tagName.c1.c2.c3....cn
22 | // input.form-control.private-form__control.login-email
23 |
24 | // Selected class values
25 | // .c1.c2.c3.....cn ==> .c1.c3.c4
26 | //.form-control.private-form__control
27 | //input.login-email
28 |
29 | // Mange order as per your choice
30 | //.c2.c4.c1
31 | // .login-email.form-control.private-form__control
32 |
33 | //===============================================================================
34 | // Can we combine id and class together
35 | // #id.class
36 | // #username.form-control.private-form__control.login-email
37 | // #username.login-email
38 | // tagName#id.class
39 | // input#username.login-email
40 |
41 | //.class#id
42 | //.login-email#username
43 | //tagName.class#id
44 | // input.login-email#username
45 |
46 | // Identify webElement using css without class or id [ by using other available attributes]
47 | // tagName[attribute='value']
48 | // input[type='email']
49 |
50 | // Multiple Attributes
51 | //tagName[attribute1='value1'][attribute2='value2'][attribute3='value3']......[attributeN='valueN']
52 | // input[name='firstname'][type='text'][id='input-firstname']
53 |
54 | // Can we use id or class with other attributes
55 | // #id[attribute='value']
56 | // #input-firstname[name='firstname']
57 |
58 | // .class[attribute='value']
59 | //.form-control[name='firstname']
60 |
61 | // tagName#id[attribute='value']
62 | //input#input-firstname[name='firstname']
63 |
64 | // tagName.class[attribute='value']
65 | //input.form-control[name='firstname']
66 |
67 | // Can we use text in CSS to create CSS locator
68 | // 1. Text is not supported in CSS
69 |
70 | // Contains in CSS
71 | //tagName[attribute*='attributeValue']
72 | // input[name*='firstname']
73 | // input[name*='name']
74 | // input[name*='first']
75 |
76 | // starts with in Css
77 | //tagName[attribute^='attributeValue']
78 | // input[name^='f']
79 |
80 | // ends with
81 | //tagName[attribute$='attributeValue']
82 | // input[name$='me']
83 |
84 | // parent child
85 | // parentTagName childTagName
86 | // div[class='private-form__input-wrapper'] input[type='email']
87 | // select#Form_getForm_Country option
88 |
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/Day5_Revision/HandlingDropdown.java:
--------------------------------------------------------------------------------
1 | package Day5_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.support.ui.Select;
9 |
10 | public class HandlingDropdown {
11 |
12 | public static void main(String[] args) {
13 |
14 | ChromeOptions options = new ChromeOptions();
15 | options.addArguments("--remote-allow-origins=*");
16 | WebDriver driver = new ChromeDriver(options);
17 | driver.get("https://www.orangehrm.com/contact-sales/");
18 | driver.manage().window().maximize();
19 | WebElement countryDdl = driver.findElement(By.xpath("//select[@id='Form_getForm_Country']"));
20 | Select country = new Select(countryDdl);
21 | //country.selectByIndex(12);
22 | //country.selectByValue("India");
23 | country.selectByVisibleText("Brazil");
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Day5_Revision/HandlingDropdown2.java:
--------------------------------------------------------------------------------
1 | package Day5_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.support.ui.Select;
9 |
10 | import java.util.List;
11 |
12 | public class HandlingDropdown2 {
13 |
14 | public static void main(String[] args) {
15 |
16 | ChromeOptions options = new ChromeOptions();
17 | options.addArguments("--remote-allow-origins=*");
18 | WebDriver driver = new ChromeDriver(options);
19 | driver.get("https://www.orangehrm.com/contact-sales/");
20 | driver.manage().window().maximize();
21 | WebElement countryDdl = driver.findElement(By.xpath("//select[@id='Form_getForm_Country']"));
22 | Select country = new Select(countryDdl);
23 | List countrylist = country.getOptions();
24 | for (WebElement nation : countrylist) {
25 | String countryName = nation.getText();
26 | if (countryName.equalsIgnoreCase("Australia")) {
27 | nation.click();
28 | break;
29 | }
30 | }
31 |
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Day5_Revision/HandlingDropdown3.java:
--------------------------------------------------------------------------------
1 | package Day5_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.support.ui.Select;
9 |
10 | import java.util.List;
11 |
12 | public class HandlingDropdown3 {
13 |
14 | public static void main(String[] args) {
15 |
16 | ChromeOptions options = new ChromeOptions();
17 | options.addArguments("--remote-allow-origins=*");
18 | WebDriver driver = new ChromeDriver(options);
19 | driver.get("https://www.hdfcbank.com/");
20 | driver.manage().window().maximize();
21 | WebElement productTypeDdl = driver.findElement(By.xpath("//a[text()='Select Product Type']"));
22 | productTypeDdl.click();
23 | List productType = driver.findElements(By.xpath("//div[@class='dropdown open']//li"));
24 |
25 | for (WebElement product : productType) {
26 | String productName = product.getText();
27 | if (productName.equalsIgnoreCase("Loans")) {
28 | product.click();
29 | break;
30 | }
31 | }
32 |
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Day6_Revision/CaptureScreenshot.java:
--------------------------------------------------------------------------------
1 | package Day6_Revision;
2 |
3 | import org.apache.commons.io.FileUtils;
4 | import org.openqa.selenium.OutputType;
5 | import org.openqa.selenium.TakesScreenshot;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.chrome.ChromeDriver;
8 | import org.openqa.selenium.chrome.ChromeOptions;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 |
13 | public class CaptureScreenshot {
14 |
15 | public static void main(String[] args) throws IOException {
16 | ChromeOptions options = new ChromeOptions();
17 | options.addArguments("--remote-allow-origins=*");
18 | WebDriver driver = new ChromeDriver(options);
19 | driver.manage().window().maximize();
20 | driver.get("https://www.salesforce.com/au/");
21 |
22 | // Take the screenshot and save to a file
23 | TakesScreenshot ts = (TakesScreenshot) driver;
24 | File src = ts.getScreenshotAs(OutputType.FILE);
25 |
26 | // Save the screenshot to a specified location
27 | File target = new File("C:\\Users\\91886\\Pictures\\Screenshots\\salesforce.png");
28 | FileUtils.copyFile(src, target);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Day6_Revision/HandlingDatePicker.java:
--------------------------------------------------------------------------------
1 | package Day6_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 |
9 | import java.util.List;
10 |
11 | public class HandlingDatePicker {
12 |
13 | public static void main(String[] args) {
14 |
15 | ChromeOptions options = new ChromeOptions();
16 | options.addArguments("--remote-allow-origins=*");
17 | WebDriver driver = new ChromeDriver(options);
18 | driver.manage().window().maximize();
19 | driver.get("https://www.redbus.in/");
20 |
21 | //1. Identify the date that i want to select
22 | String year = "2023";
23 | String month = "Aug";
24 | String date = "19";
25 |
26 | //2. Click on Calender
27 | driver.findElement(By.xpath("//input[@id='onward_cal']")).click();
28 |
29 | while(true)
30 | {
31 | //3. Capture Year and Month
32 | String monthYear=driver.findElement(By.xpath("//td[@class='monthTitle']")).getText();
33 | String [] ym=monthYear.split(" ");
34 | if(ym[0].equalsIgnoreCase(month) && ym[1].equalsIgnoreCase(year))
35 | {
36 | // perform some operation
37 | List dates= driver.findElements(By.xpath("//table[@class='rb-monthTable first last']//tr/td"));
38 | for(WebElement dt : dates)
39 | {
40 | if(dt.getText().equals(date))
41 | {
42 | dt.click();
43 | break;
44 | }
45 | }
46 | }
47 | else
48 | {
49 | driver.findElement(By.xpath("//td[@class='next']")).click();
50 | }
51 |
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/Day6_Revision/HandlingDragDrop.java:
--------------------------------------------------------------------------------
1 | package Day6_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.interactions.Actions;
9 |
10 | public class HandlingDragDrop {
11 |
12 | public static void main(String[] args) {
13 | ChromeOptions options = new ChromeOptions();
14 | options.addArguments("--remote-allow-origins=*");
15 | WebDriver driver = new ChromeDriver(options);
16 | driver.get("http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html");
17 |
18 | WebElement sourceCapital = driver.findElement(By.xpath("//div[text()='Rome' and @id='box6']"));
19 | WebElement destinationCountry = driver.findElement(By.xpath("//div[text()='Italy']"));
20 |
21 | Actions act = new Actions(driver);
22 | act.dragAndDrop(sourceCapital, destinationCountry).perform();
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Day6_Revision/HandlingExpliciteWait.java:
--------------------------------------------------------------------------------
1 | package Day6_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 | import org.openqa.selenium.support.ui.ExpectedConditions;
9 | import org.openqa.selenium.support.ui.WebDriverWait;
10 |
11 | import java.time.Duration;
12 |
13 | public class HandlingExpliciteWait {
14 |
15 | public static void main(String[] args) {
16 | ChromeOptions options = new ChromeOptions();
17 | options.addArguments("--remote-allow-origins=*");
18 | WebDriver driver = new ChromeDriver(options);
19 | driver.manage().window().maximize();
20 | driver.get("http://janbaskdemo.com/");
21 | driver.findElement(By.xpath("//i[@class='fa fa-user']")).click();
22 | WebElement loginLink = driver.findElement(By.xpath("//a[text()='Login']"));
23 | WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(2000));
24 | wait.until(ExpectedConditions.elementToBeClickable(loginLink));
25 | loginLink.click();
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/Day6_Revision/HandlingIFrame.java:
--------------------------------------------------------------------------------
1 | package Day6_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.chrome.ChromeOptions;
7 |
8 | public class HandlingIFrame {
9 |
10 | public static void main(String[] args) {
11 | ChromeOptions options = new ChromeOptions();
12 | options.addArguments("--remote-allow-origins=*");
13 | WebDriver driver = new ChromeDriver(options);
14 | driver.manage().window().maximize();
15 | driver.get("https://www.selenium.dev/selenium/docs/api/java/index.html?overview-summary.html");
16 |
17 | //1. Switch to first frame
18 | driver.switchTo().frame("packageListFrame");
19 |
20 | //2. Click on element in the first frame
21 | driver.findElement(By.xpath("//a[text()='org.openqa.selenium.bidi' and @target='packageFrame']")).click();
22 |
23 | //3 . Move out of first frame
24 | driver.switchTo().defaultContent();
25 |
26 | //4. Switch to second frame
27 | driver.switchTo().frame("packageFrame");
28 |
29 | //5. Click on element in second frame
30 | driver.findElement(By.xpath("//span[text()='HasBiDi']")).click();
31 |
32 | //6. Move out of second frame
33 | driver.switchTo().defaultContent();
34 |
35 | //7. Switch to third frame
36 | driver.switchTo().frame("classFrame");
37 |
38 | //8. Click on element in the third frame
39 | driver.findElement(By.xpath("//a[text()='FirefoxDriver']")).click();
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Day6_Revision/HandlingImpliciteWait.java:
--------------------------------------------------------------------------------
1 | package Day6_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.chrome.ChromeOptions;
7 |
8 | import java.time.Duration;
9 |
10 | public class HandlingImpliciteWait {
11 |
12 | public static void main(String[] args) {
13 | ChromeOptions options = new ChromeOptions();
14 | options.addArguments("--remote-allow-origins=*");
15 | WebDriver driver = new ChromeDriver(options);
16 | driver.manage().window().maximize();
17 | driver.get("http://janbaskdemo.com/");
18 |
19 | driver.findElement(By.xpath("//i[@class='fa fa-user']")).click();
20 | driver.manage().timeouts().implicitlyWait(Duration.ofMillis(2000));
21 | driver.findElement(By.xpath("//a[text()='Login']")).click();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/Day6_Revision/HandlingWindows.java:
--------------------------------------------------------------------------------
1 | package Day6_Revision;
2 |
3 | import org.openqa.selenium.By;
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.WebElement;
6 | import org.openqa.selenium.chrome.ChromeDriver;
7 | import org.openqa.selenium.chrome.ChromeOptions;
8 |
9 | import java.util.Set;
10 |
11 | public class HandlingWindows {
12 |
13 | public static void main(String[] args) {
14 | ChromeOptions options = new ChromeOptions();
15 | options.addArguments("--remote-allow-origins=*");
16 | WebDriver driver = new ChromeDriver(options);
17 | driver.manage().window().maximize();
18 | driver.get("https://www.salesforce.com/au/");
19 | WebElement freeTrialBtn = driver.findElement(By.xpath("(//a[contains(@aria-label, 'Start my free')])[1]"));
20 | freeTrialBtn.click();
21 |
22 | Set windowIds = driver.getWindowHandles();
23 | for (String id : windowIds) {
24 | driver.switchTo().window(id);
25 | if (driver.getTitle().contains("Free CRM")) {
26 | driver.findElement(By.name("UserFirstName")).sendKeys("Ashish");
27 | driver.findElement(By.name("UserLastName")).sendKeys("Mishra");
28 | }
29 | }
30 |
31 |
32 | driver.quit();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/seleniumbasics/03MarchWedNesday:
--------------------------------------------------------------------------------
1 | 1- Xpath [ Relative/Absolute]
2 | //tagName[@attributeName='value']
3 | //tagName[text()='innerText']
4 | //tagName[contains(@AttributeName/text(), 'attributeValue/InnerText')]
5 |
6 | Talk about absolute path and Relative path with more examples
7 |
--------------------------------------------------------------------------------
/src/seleniumbasics/BrowserClose.java:
--------------------------------------------------------------------------------
1 | package seleniumbasics;
2 |
3 | import org.openqa.selenium.WebDriver;
4 | import org.openqa.selenium.chrome.ChromeDriver;
5 | import org.openqa.selenium.chrome.ChromeOptions;
6 | import org.openqa.selenium.edge.EdgeDriver;
7 |
8 | public class BrowserClose {
9 | public static void main(String[] args) {
10 | // ChromeOptions options = new ChromeOptions();
11 | // options.addArguments("--remote-allow-origins=*");
12 | WebDriver driver = new EdgeDriver();
13 | driver.get("https://www.facebook.com/");
14 | driver.close();
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/seleniumbasics/CapturePageSource.java:
--------------------------------------------------------------------------------
1 | package seleniumbasics;
2 |
3 | import org.openqa.selenium.WebDriver;
4 | import org.openqa.selenium.chrome.ChromeDriver;
5 |
6 | public class CapturePageSource {
7 |
8 | public static void main(String[] args) {
9 | WebDriver driver = new ChromeDriver();
10 | driver.get("https://www.facebook.com/");
11 | String pageSource= driver.getPageSource();
12 | System.out.println(pageSource);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/seleniumbasics/CaptureTitle.java:
--------------------------------------------------------------------------------
1 | package seleniumbasics;
2 |
3 | import org.openqa.selenium.WebDriver;
4 | import org.openqa.selenium.chrome.ChromeDriver;
5 |
6 | public class CaptureTitle {
7 |
8 | public static void main(String[] args) {
9 | WebDriver driver = new ChromeDriver();
10 | driver.get("https://www.google.com/"); // Chrome
11 | driver.navigate().to("https://www.facebook.com/");
12 |
13 | String pageTitle=driver.getTitle();
14 | System.out.println("The title of the page is : " + pageTitle);
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/seleniumbasics/CaptureUrl.java:
--------------------------------------------------------------------------------
1 | package seleniumbasics;
2 |
3 | import org.openqa.selenium.WebDriver;
4 | import org.openqa.selenium.chrome.ChromeDriver;
5 |
6 | public class CaptureUrl {
7 |
8 | public static void main(String[] args) {
9 | WebDriver driver = new ChromeDriver();
10 | driver.get("https://www.facebook.com/");
11 | String pageUrl= driver.getCurrentUrl();
12 | System.out.println("Page URL : " + pageUrl);
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/seleniumbasics/LaunchApplication.java:
--------------------------------------------------------------------------------
1 | package seleniumbasics;
2 |
3 | import org.openqa.selenium.WebDriver;
4 | import org.openqa.selenium.chrome.ChromeDriver;
5 |
6 | public class LaunchApplication {
7 |
8 | public static void main(String[] args) {
9 | //1. Open the Browser
10 | System.setProperty("webdriver.chrome.driver", "C:\\Users\\91886\\IdeaProjects\\LearningSeleniumBasics\\Drivers\\chromedriver.exe");
11 | WebDriver driver = new ChromeDriver();
12 | driver.get("https://www.google.com");
13 |
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/seleniumbasics/LaunchApplication2.java:
--------------------------------------------------------------------------------
1 | package seleniumbasics;
2 |
3 |
4 | import org.openqa.selenium.WebDriver;
5 | import org.openqa.selenium.chrome.ChromeDriver;
6 | import org.openqa.selenium.chrome.ChromeOptions;
7 |
8 | public class LaunchApplication2 {
9 | public static void main(String[] args) {
10 | ChromeOptions options = new ChromeOptions();
11 | options.addArguments("--remote-allow-origins=*");
12 | WebDriver driver = new ChromeDriver(options);
13 |
14 | driver.get("https://google.com/");
15 | String pageTitle =driver.getTitle();
16 | System.out.println(pageTitle);
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/seleniumbasics/PageRefresh.java:
--------------------------------------------------------------------------------
1 | package seleniumbasics;
2 |
3 | import org.openqa.selenium.WebDriver;
4 | import org.openqa.selenium.chrome.ChromeDriver;
5 |
6 | public class PageRefresh {
7 |
8 | public static void main(String[] args) {
9 | WebDriver driver = new ChromeDriver();
10 | driver.get("https://www.facebook.com/");
11 | driver.navigate().refresh();
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------