How to use toString method of org.openqa.selenium.firefox.FirefoxBinary class

Best Selenium code snippet using org.openqa.selenium.firefox.FirefoxBinary.toString

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package com.seleliumDemo;
2
3import java.io.File;
4
5import org.openqa.selenium.By;
6import org.openqa.selenium.WebDriver;
7import org.openqa.selenium.WebElement;
8import org.openqa.selenium.firefox.FirefoxBinary;
9import org.openqa.selenium.firefox.FirefoxDriver;
10import org.openqa.selenium.firefox.FirefoxProfile;
11
12public class SeleniumAmazon {
13	private File pathToBinary;
14	private FirefoxBinary firefoxBinary;
15	private FirefoxProfile firefoxProfile;
16	private WebDriver driver;
17
18	@SuppressWarnings("deprecation")
19	public SeleniumAmazon() {
20		System.setProperty("webdriver.gecko.driver", "D:\\install\\webdriver\\geckodriver.exe");
21
22		// 安装路径
23		this.pathToBinary = new File("D:\\Mozilla Firefox\\firefox.exe");
24		this.firefoxBinary = new FirefoxBinary(pathToBinary);
25		this.firefoxProfile = new FirefoxProfile();
26		this.driver = new FirefoxDriver(firefoxBinary, firefoxProfile);
27	}
28
29	public static void main(String[] args) {
30		String url = "https://login.aliexpress.com/?flag=1&return_url=http%3A%2F%2Fmyae.aliexpress.com%2Fseller%2Findex.htm%3Fspm%3D2114.11010108.1000001.4.464431423RBRaD";
31		new SeleniumAmazon().getTest(url);
32	}
33
34	public void getTest(String url) {
35		driver.get(url);
36		WebElement jfram = driver.findElement(By.tagName("iframe"));
37		//WebElement name = driver.findElement(By.tagName("iframe")).findElement(By.xpath("//input[@id='fm-login-id']"));
38		System.out.println(jfram.toString());
39		driver.close();
40	}
41}
42
Full Screen
copy
1package com.test.firefox;
2
3import java.io.File;
4
5import org.openqa.selenium.WebDriver;
6import org.openqa.selenium.firefox.FirefoxBinary;
7import org.openqa.selenium.firefox.FirefoxDriver;
8import org.openqa.selenium.firefox.FirefoxProfile;
9import org.openqa.selenium.firefox.internal.ProfilesIni;
10
11public class selerun {
12	public WebDriver globalDriver;
13
14	public void tc1_selenium() {
15		try {
16			String driverPath = "E:\\AllInstallablesEXE\\OpenSource\\AutomationTesting\\Selenium\\geckodriver-v0.18.0-win32\\";
17
18			File file = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
19			FirefoxBinary fbinary = new FirefoxBinary(file);
20			ProfilesIni profiles = new ProfilesIni();
21			FirefoxProfile fp = profiles.getProfile("Selenium");
22			System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver.exe");
23			globalDriver = new FirefoxDriver(fbinary, fp);
24			globalDriver.manage().window().maximize();
25			globalDriver.get("https://dev23478.service-now.com/");
26		} catch (Exception e) {
27			System.out.println("Failure in  initializing Firefox Driver: " + e.toString());
28		}
29	}
30
31}
32
Full Screen
copy
1package Scraper;
2
3import java.io.BufferedReader;
4import java.io.File;
5import java.io.FileNotFoundException;
6import java.io.FileReader;
7import java.io.FileWriter;
8import java.io.IOException;
9import java.io.PrintWriter;
10import java.text.ParseException;
11import java.text.SimpleDateFormat;
12import java.util.Date;
13import java.util.Random;
14import java.util.concurrent.TimeUnit;
15
16import org.joda.time.DateTime;
17import org.openqa.selenium.By;
18import org.openqa.selenium.WebDriver;
19import org.openqa.selenium.firefox.FirefoxBinary;
20import org.openqa.selenium.firefox.FirefoxDriver;
21import org.openqa.selenium.firefox.FirefoxProfile;
22import org.openqa.selenium.firefox.internal.ProfilesIni;
23import org.openqa.selenium.htmlunit.HtmlUnitDriver;
24
25import Property.PropertyStructure;
26
27public class HolidayLettingScraper {
28	WebDriver driver;
29	PropertyStructure property;
30	public HolidayLettingScraper(PropertyStructure property){
31		this.property = property;
32	}
33	
34	
35	public void scrape() throws Exception{
36		if (property.holidayletting_name==null || property.holidayletting_name.equals(""))
37			return;
38		
39		scrapeCalendarData();
40		updateAvailablity();
41	}
42
43
44	private void scrapeCalendarData() throws Exception {
45		try{
46			
47			
48			ProfilesIni profilesIni = new ProfilesIni();
49			FirefoxProfile profile = profilesIni.getProfile("default");
50			profile.setAssumeUntrustedCertificateIssuer(false);
51//			final File firefoxPath = new File(System.getProperty(
52//	                "lmportal.deploy.firefox.path", "/usr/bin/firefox"));
53//
54//			if (firefoxPath.exists()){
55//				String Xport = System.getProperty(
56//		                "lmportal.xvfb.id", ":1");
57//		        FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
58//		        firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
59//		        this.driver =  new FirefoxDriver(firefoxBinary, profile);
60//			} else{
61				this.driver =  new FirefoxDriver(profile);	
62//			}
63			
64	//		this.driver = new HtmlUnitDriver();
65			String baseUrl = "https://www.holidaylettings.co.uk/";
66		    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
67		    driver.get(baseUrl + "/");
68		    
69		    driver.get(baseUrl + "content/login");
70//		    driver.findElement(By.xpath("(//a[contains(text(),'Owner login')])[2]")).click();
71		    driver.findElement(By.id("ownerId")).clear();
72		    driver.findElement(By.id("ownerId")).sendKeys("[email protected]");
73		    driver.findElement(By.id("ownerPassword")).clear();
74		    driver.findElement(By.id("ownerPassword")).sendKeys("samiul123");
75		    driver.findElement(By.xpath("//div[@id='ownerLoginForm']/button")).click();
76		    Thread.sleep(5000);
77		    driver.findElement(By.linkText("Properties")).click();
78		    Thread.sleep(1000);
79		    driver.findElement(By.linkText("Update calendar")).click();
80		    
81		    driver.findElement(By.id("calendarContainer"));
82		    int randomtry = new Random().nextInt((10 - 5) + 1) + 5;
83		    for (int i =0; i <randomtry; i++){
84		    	driver.findElement(By.cssSelector("span.ui-selectmenu-status")).click();
85			    driver.findElement(By.xpath("//a[contains(text(),'"+property.holidayletting_name+"')]")).click();
86			    Thread.sleep(5000);
87		    }
88		    driver.findElement(By.id("calendarContainer"));
89		    printToFile(driver.getPageSource());
90		    driver.quit();
91		} catch (Exception e){
92			e.printStackTrace();
93			driver.quit();
94			throw new Exception();
95		} 
96	}
97	
98	private void printToFile(String s) throws IOException{
99		String localFileName = "/tmp/holidayletting.data";
100		File f = new File(localFileName);
101		if (f.exists()) f.delete();
102		FileWriter fw = new FileWriter(localFileName);
103		PrintWriter pw = new PrintWriter(fw);
104		String[] tmp = s.split("\\n");
105		for (int i =0; i < tmp.length;i++){
106			if (tmp[i].contains("data-cell-date")){
107				String p1 = tmp[i].split("class=")[0];
108				p1 = p1.split("\"")[1];
109				p1 = p1.trim();
110				String p2 = tmp[i].split("class=")[1];
111				p2 = p2.split(">")[0];
112				p2 = p2.replace("\"", "");
113				p2 = p2.trim();
114				if (p2.equals("ab") || p2.equals("ah") || p2.equals("b") || p2.equals("h") || p2.equals("rb") || p2.equals("rh") || p2.equals("hb") || p2.equals("bh") )
115					pw.println(p1 + " " + p2);
116			}
117		}
118		pw.close();
119		fw.close();
120		
121	}
122	
123	private void updateAvailablity() throws IOException, ParseException{
124		FileReader fr = new FileReader("/tmp/holidayletting.data");
125		BufferedReader br = new BufferedReader(fr);
126		String line = "";
127		
128		while ((line = br.readLine())!= null){
129			line = line.split(" ")[0];
130			SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyy"); 			
131			Date d = dt.parse(line);
132			DateTime date = new DateTime(d);
133			if (!(date.plusDays(1)).isBefore(System.currentTimeMillis())){
134				property.add_HolidayLetting_Availablity(date.toString().split("T")[0]);
135				System.out.println(date.toString().split("T")[0]);
136			}
137		}
138		br.close();
139		fr.close();
140		
141	}
142
143}
144
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger toString code on LambdaTest Cloud Grid

Execute automation tests with toString on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie