|
| 1 | +package SeleniumSessions; |
| 2 | + |
| 3 | +import java.util.concurrent.TimeUnit; |
| 4 | + |
| 5 | +import org.openqa.selenium.By; |
| 6 | +import org.openqa.selenium.WebDriver; |
| 7 | +import org.openqa.selenium.chrome.ChromeDriver; |
| 8 | + |
| 9 | +public class DynamicWebTableHandle { |
| 10 | + |
| 11 | + public static void main(String[] args) throws InterruptedException { |
| 12 | + |
| 13 | + |
| 14 | + System.setProperty("webdriver.chrome.driver", "/Users/naveenkhunteta/Downloads/chromedriver"); |
| 15 | + |
| 16 | + WebDriver driver = new ChromeDriver(); // launch chrome |
| 17 | + |
| 18 | + driver.manage().window().maximize(); // maximize window |
| 19 | + driver.manage().deleteAllCookies(); // delete all the cookies |
| 20 | + |
| 21 | + // dynamic wait |
| 22 | + driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS); |
| 23 | + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); |
| 24 | + |
| 25 | + driver.get("https://www.freecrm.com/"); // enter URL |
| 26 | + |
| 27 | + driver.findElement(By.name("username")).sendKeys("naveenk"); |
| 28 | + driver.findElement(By.name("password")).sendKeys("test@123"); |
| 29 | + Thread.sleep(3000); |
| 30 | + |
| 31 | + driver.findElement(By.xpath("//input[@type='submit']")).click(); |
| 32 | + |
| 33 | + driver.switchTo().frame("mainpanel"); |
| 34 | + Thread.sleep(2000); |
| 35 | + |
| 36 | + driver.findElement(By.xpath("//a[contains(text(),'Contacts')]")).click(); |
| 37 | + |
| 38 | + //*[@id='vContactsForm']/table/tbody/tr[4]/td[2]/a |
| 39 | + //*[@id='vContactsForm']/table/tbody/tr[5]/td[2]/a |
| 40 | + //*[@id='vContactsForm']/table/tbody/tr[6]/td[2]/a |
| 41 | + //*[@id='vContactsForm']/table/tbody/tr[7]/td[2]/a |
| 42 | + |
| 43 | + |
| 44 | + //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 | +// } |
| 56 | + |
| 57 | + //Method-2: |
| 58 | + driver.findElement(By.xpath("//a[contains(text(),'test2 test2')]/parent::td//preceding-sibling::td//input[@name='contact_id']")).click(); |
| 59 | + driver.findElement(By.xpath("//a[contains(text(),'ui uiii')]/parent::td//preceding-sibling::td//input[@name='contact_id']")).click(); |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | +} |
0 commit comments