I need to start my JAVA Selenium code in current Window of Firefox. But when I start my code WebDriver driver = new FirefoxDriver();
will open new window! Don't need open new window!
In Selenium IDE code works in current window of browser.
package tm.csgo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Item {
public String siteUrl;
public String url;
public String name;
public int bought;
public int needCount;
public int wantPrice;
public double price;
public void buyProcess() {
System.out.println("Начало покупки, запуск браузера...");
System.out.println("Запланировано приобрести " + needCount + " " + name + " предметов.");
WebDriver driver = new FirefoxDriver();
while(bought <= needCount){
System.out.println("Приобретаем " + bought + " предмет");
driver.get(siteUrl + url);
price = Double.parseDouble(driver.findElement(By.className("ip-bestprice")).getText());
System.out.println("Стоимость предмета " + name + ": " + price + " рублей");
if (price <= wantPrice) {
System.out.println("Покупаем " + name + "...");
driver.findElement(By.cssSelector("a.buy-pic-button")).click();
driver.findElement(By.id("info_dialog_url")).click();
} else {
continue;
}
System.out.println("Приобретён " + bought + " предмет за " + price + " рублей из " + needCount + " запланированных предметов");
bought++;
}
}
public void purchaseReady() {
//дописать общую сумму затрат
System.out.println("Приобретено предметов на сумму ...");
System.out.println("Покупка успешно завершена!");
}
}