Skip to content

Commit 0799699

Browse files
author
Naveen Khunteta
committed
added calendar handling code
1 parent 9767521 commit 0799699

10 files changed

+195
-11
lines changed
4.14 KB
Binary file not shown.
823 Bytes
Binary file not shown.
2.87 KB
Binary file not shown.
0 Bytes
Binary file not shown.
2.56 KB
Binary file not shown.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package SeleniumSessions;
2+
3+
import java.util.concurrent.TimeUnit;
4+
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.NoSuchElementException;
7+
import org.openqa.selenium.WebDriver;
8+
import org.openqa.selenium.chrome.ChromeDriver;
9+
import org.openqa.selenium.support.ui.Select;
10+
11+
public class CalendarSelectTest {
12+
13+
public static void main(String[] args) throws InterruptedException {
14+
15+
System.setProperty("webdriver.chrome.driver", "/Users/naveenkhunteta/Downloads/chromedriver");
16+
17+
WebDriver driver = new ChromeDriver(); // launch chrome
18+
19+
driver.manage().window().maximize(); // maximize window
20+
driver.manage().deleteAllCookies(); // delete all the cookies
21+
22+
//dynamic wait
23+
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
24+
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
25+
26+
driver.get("https://www.freecrm.com/"); // enter URL
27+
28+
driver.findElement(By.name("username")).sendKeys("naveenk");
29+
driver.findElement(By.name("password")).sendKeys("test@123");
30+
Thread.sleep(3000);
31+
driver.findElement(By.xpath("//input[@type='submit']")).click(); //login button
32+
33+
driver.switchTo().frame("mainpanel");
34+
35+
String date = "32-May-2017";
36+
String dateArr[] = date.split("-"); // {18,September,2017}
37+
String day = dateArr[0];
38+
String month = dateArr[1];
39+
String year = dateArr[2];
40+
41+
Select select = new Select(driver.findElement(By.name("slctMonth")));
42+
select.selectByVisibleText(month);
43+
44+
Select select1 = new Select(driver.findElement(By.name("slctYear")));
45+
select1.selectByVisibleText(year);
46+
47+
//*[@id='crmcalendar']/table/tbody/tr[2]/td/table/tbody/tr[2]/td[1]
48+
//*[@id='crmcalendar']/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]
49+
//*[@id='crmcalendar']/table/tbody/tr[2]/td/table/tbody/tr[2]/td[6]
50+
51+
String beforeXpath = "//*[@id='crmcalendar']/table/tbody/tr[2]/td/table/tbody/tr[";
52+
String afterXpath = "]/td[";
53+
54+
final int totalWeekDays = 7;
55+
56+
//2-1 2-2 2-3 2-4 2-5 2-6 2-7
57+
//3-2 3-2 3-3 3-4 3-5 3-6 3-7
58+
boolean flag = false;
59+
String dayVal = null;
60+
for(int rowNum=2; rowNum<=7; rowNum++){
61+
62+
for(int colNum = 1; colNum<=totalWeekDays; colNum++){
63+
try{
64+
dayVal =driver.findElement(By.xpath(beforeXpath+rowNum+afterXpath+colNum+"]")).getText();
65+
}catch (NoSuchElementException e){
66+
System.out.println("Please enter a correct date value");
67+
flag = false;
68+
break;
69+
}
70+
System.out.println(dayVal);
71+
if(dayVal.equals(day)){
72+
driver.findElement(By.xpath(beforeXpath+rowNum+afterXpath+colNum+"]")).click();
73+
flag = true;
74+
break;
75+
}
76+
}
77+
if(flag){
78+
break;
79+
}
80+
81+
}
82+
83+
84+
}
85+
86+
}

src/SeleniumSessions/DynamicWebTableHandle.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ public static void main(String[] args) throws InterruptedException {
4242

4343

4444
//Method-1:
45-
// String before_xpath = "//*[@id='vContactsForm']/table/tbody/tr[";
46-
// String after_xpath = "]/td[2]/a";
47-
//
48-
// for(int i=4; i<=7; i++){
49-
// String name = driver.findElement(By.xpath(before_xpath + i + after_xpath)).getText();
50-
// System.out.println(name);
51-
// if(name.contains("test2 test2")){ //i=6
52-
// //*[@id='vContactsForm']/table/tbody/tr[6]/td[1]/input
53-
// driver.findElement(By.xpath("//*[@id='vContactsForm']/table/tbody/tr["+i+"]/td[1]/input")).click();
54-
// }
55-
// }
45+
String before_xpath = "//*[@id='vContactsForm']/table/tbody/tr[";
46+
String after_xpath = "]/td[2]/a";
47+
48+
for(int i=4; i<=7; i++){
49+
String name = driver.findElement(By.xpath(before_xpath + i + after_xpath)).getText();
50+
System.out.println(name);
51+
if(name.contains("test2 test2")){ //i=6
52+
//*[@id='vContactsForm']/table/tbody/tr[6]/td[1]/input
53+
driver.findElement(By.xpath("//*[@id='vContactsForm']/table/tbody/tr["+i+"]/td[1]/input")).click();
54+
}
55+
}
5656

5757
//Method-2:
5858
driver.findElement(By.xpath("//a[contains(text(),'test2 test2')]/parent::td//preceding-sibling::td//input[@name='contact_id']")).click();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package SeleniumSessions;
2+
3+
import java.util.List;
4+
import java.util.concurrent.TimeUnit;
5+
6+
import org.openqa.selenium.By;
7+
import org.openqa.selenium.WebDriver;
8+
import org.openqa.selenium.WebElement;
9+
import org.openqa.selenium.chrome.ChromeDriver;
10+
11+
public class GoogleSearchTest {
12+
13+
public static void main(String[] args) {
14+
15+
System.setProperty("webdriver.chrome.driver", "/Users/naveenkhunteta/Downloads/chromedriver");
16+
17+
WebDriver driver = new ChromeDriver(); // launch chrome
18+
19+
driver.manage().window().maximize(); // maximize window
20+
driver.manage().deleteAllCookies(); // delete all the cookies
21+
22+
// dynamic wait
23+
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
24+
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
25+
26+
driver.get("http://www.google.com");
27+
28+
driver.findElement(By.id("lst-ib")).sendKeys("Java");
29+
30+
List<WebElement> list = driver.findElements(By.xpath("//ul[@role='listbox']//li/descendant::div[@class='sbqs_c']"));
31+
32+
System.out.println("total number of suggestions in search box:::===>" + list.size());
33+
34+
for(int i=0; i<list.size(); i++){
35+
System.out.println(list.get(i).getText());
36+
if(list.get(i).getText().contains("java tutorial")){
37+
list.get(i).click();
38+
break;
39+
}
40+
41+
}
42+
43+
44+
45+
}
46+
47+
}

src/SeleniumSessions/MouseMovementConcept.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public static void main(String[] args) throws InterruptedException {
2525

2626
driver.findElement(By.linkText("Fleet")).click();
2727

28+
//a[contains(text(),'Sales')]
29+
2830

2931
}
3032

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package SeleniumSessions;
2+
3+
import java.util.concurrent.TimeUnit;
4+
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.JavascriptExecutor;
7+
import org.openqa.selenium.WebDriver;
8+
import org.openqa.selenium.WebElement;
9+
import org.openqa.selenium.chrome.ChromeDriver;
10+
11+
import com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutor;
12+
13+
14+
public class SelectCalendarByJS {
15+
16+
public static void main(String[] args) {
17+
18+
System.setProperty("webdriver.chrome.driver", "/Users/naveenkhunteta/Downloads/chromedriver");
19+
20+
WebDriver driver = new ChromeDriver(); // launch chrome
21+
22+
driver.manage().window().maximize(); // maximize window
23+
driver.manage().deleteAllCookies(); // delete all the cookies
24+
25+
//dynamic wait
26+
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
27+
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
28+
29+
driver.get("http://spicejet.com/"); // enter URL
30+
31+
WebElement date = driver.findElement(By.id("ctl00_mainContent_txt_Fromdate"));
32+
String dateVal = "30-12-2017";
33+
34+
selectDateByJS(driver, date, dateVal);
35+
36+
}
37+
38+
39+
public static void selectDateByJS(WebDriver driver, WebElement element, String dateVal){
40+
JavascriptExecutor js = ((JavascriptExecutor) driver);
41+
js.executeScript("arguments[0].setAttribute('value','"+dateVal+"');", element);
42+
43+
}
44+
45+
46+
47+
48+
49+
}

0 commit comments

Comments
 (0)