I am running a simple code to open google.co.uk in a firefox broswer but after the running the code in eclipse, it only opens up the browser stops there. Please help. Here's the code-
package basic_webdriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Driver_Test {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("https://www.google.co.uk/");
System.out.println(driver.getTitle());
}
}
Try
driver.Navigate().GoToUrl("https://www.google.co.uk/");
The Navigate function tells the browser to navigate somewhere.
The GoToURL function indicates that the browser should navigate to a specific URL.
The string for the URL is input as a parameter for the GoToURL.
The above should make the browser navigate to a specific URL.
Related
I have a problem that I cannot launch my JxBrowser from another class but it works fine on its own class. I will give the code for the internet browser class here
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import javax.swing.*;
import java.awt.*;
public class InternetBrowser
{
//properties
Browser browser;
BrowserView browserView;
JFrame frame;
//constructor
public InternetBrowser()
{
browser = new Browser();
browserView = new BrowserView(browser);
frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("https://www.youtube.com/embed/bO7yYDIOuXo");
}
public static void main( String [] args )
{
InternetBrowser browser = new InternetBrowser();
}
}
The error that I get is
Class StartIPCTask is implemented in both /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/jxmaps-chromium-49.0.2623.110.unknown/data/Temp/libjxmaps-common64-397f2f15-9ac5-4806-91f6-88c8aaa29714.dylib (0x1288d5630) and /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/browsercore-64.0.3282.24.6.21/data/Temp/libbrowsercore-common64-01e73e7f-2b85-4bd3-ac76-05d908fa4928.dylib (0x16b2576c8). One of the two will be used. Which one is undefined.
I need to define which one of the directories that the class should use but I do not know how. I am using the latest version of Netbeans. Also at the top of the class that im trying to construct a browser, the imports are highlighted as "unused import". Thank you for your help!
I realized that this is a bug seen in OSX.. The program works without any problem in windows computers.
In general, this warning doesn't affect the program, so you can just ignore it. If you don't want to receive it at all, then please try using the jxbrowser.jni.singleton.fix=false VM parameter.
I'm getting a popup for downloading the fonts files(ttf) in a spring-boot application, the font file is related to bootstrap3.
I tried to add MimeTypes like this but still getting the popup for first time I open the application.
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.stereotype.Component;
#Component
public class ServletCustomizer implements EmbeddedServletContainerCustomizer {
#Override
public void customize(ConfigurableEmbeddedServletContainer container) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("woff","application/x-font-woff");
mappings.add("eot","application/vnd.ms-fontobject");
mappings.add("ttf","application/x-font-ttf");
container.setMimeMappings(mappings);
}
}
I'm using Spring-boot 1.3.3.RELEASE+thymeleaf.
Anyone know how to resolve this issue?
I resolved the issue by adding this line to my security config
http.authorizeRequests().antMatchers("/fonts/**").permitAll();
Is it possible to run JavaFx in headless mode(in Java 7)? It is being used to generate images on the server but is asking for an X-Server. Does there exist something like java.awt.headless in JavaFx ?(I can't use Xvfb )
Here is how I solved this problem for server-side image geneartion on Ubuntu linux environment with jetty application server. It uses xvfb but only as a "library" - without any additional special actions on server:
apt-get install xvfb
// then on application server start:
export DISPLAY=":99"
start-stop-daemon --start --background --user jetty --exec "/usr/bin/sudo" -- -u jetty /usr/bin/Xvfb :99 -screen 0 1024x768x24
You can see the details of my server-side image generation solution in this SO question.
This is a kind of problem which I encountered while capturing images in Mac OS.
I have solved this issue by using
static {
System.setProperty("java.awt.headless", "false");
}
See for reference : Headless environment error in java.awt.Robot class with MAC OS
Answer by Shreyas Dave didn't work for me anymore. Though I don't know why, here is what I did:
public static void main(String[] args) {
// to avoid
// [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode.
System.setProperty("javafx.macosx.embedded", "true");
java.awt.Toolkit.getDefaultToolkit();
// end
launch(args);
}
This was also pointed out here: JavaFX screencapture headless exception on OSX
If you have the source code of the JavaFX application you could also try to use TestFX run the application in a headless mode, to control it and to make screenshots. To run your TestFX application in headless mode you have to start it with the following JVM parameters (to enable Monocle):
-Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw
Moreover you might need to install Monocle first. See Headless testing with JavaFx and TestFx for more information.
I have an application that can be used interactively (displaying JavaFx dialogs) but also must be able to run non-interactive on a server without display.
Even though no GUI element is used in non-interactive mode, we got
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:68)
This happens as soon as a class derived from javafx.application.Application is instantiated, which you normally do with your main class.
Here is the way I solved the problem:
I created an additional class GuiAppExecution:
import java.util.List;
import javafx.application.Application;
import javafx.stage.Stage;
/**
* JavaFx launch class for {#link AppExecution}.
*/
public class GuiAppExecution extends Application {
#Override
public void start(Stage stage) throws Exception {
List<String> parameters = getParameters().getRaw();
AppExecution appExecution = new AppExecution();
appExecution.launch(parameters);
}
/**
* Launches the {#link AppExecution} as JavaFx {#link Application}.
*
* #param parameters program parameters
*/
public void launchGui(String[] parameters) {
launch(parameters);
}
}
In the main class AppExecution I created a method
public void launch(List<String> parameters) {
which parses the parameters and launches the application for both interactive and non-interactive execution.
The main method looks like this:
public static void main(String[] parameters) {
List<String> parameterList = Arrays.asList(parameters);
if (parameterList.stream().anyMatch(p -> p.equalsIgnoreCase(BATCH_PARAMETER))) {
AppExecution appExecution = new AppExecution();
appExecution.launch(parameterList);
}
else {
GuiAppExecution guiAppExecution = new GuiAppExecution();
guiAppExecution.launchGui(parameters);
}
}
with
private static final String BATCH_PARAMETER = "-batch";
as the program option that request the non-interactive execution.
Since GuiAppExecution (which is derived from javafx.application.Application) is not instantiated for non-interactive execution, the JavaFx environment is not started.
My code for saving screenshot file is:
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\screenshots\\"+Filename+".jpg"));
The Error is :
The method copyFile (File, File)is undefined for the type FileUtil
I use an EventFiringWebDriver . Any ideas on this.
There are two possible explanations.
The error message you provided mentions FileUtil class instead of FileUtils You may have used wrong class by mistake.
Assuming you are using the correct FileUtils class you may have imported wrong package. Make sure that you have imported org.apache.commons.io.FileUtils
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
I guess you missed one or more of these imports.. The code given above works fine for me with these includes.
Plz put the exception then it will work fine.
EG: public static void main(String[] args) throws IOException
public class Testscreenshot {
public static void main(String[] args) throws IOException {
System.out.println("Images saved ..");
WebDriver driver = new FirefoxDriver();
driver.get("https://google");
File scrFile;
scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(scrFile, new File("C:\\Users\\R&D\\Desktop\\Tulas\\Javafiles\\testimages.png"));
driver.quit();
}
}
Use import org.apache.commons.io.FileUtils.
This imports the FileUtils class you need.
I am a newbie with webdriver and need some help..
I am using Selenium 2.2.0 with FF v7.0.1 on Windows XP
I've managed to record and play back a java script successfully in IE but whenever I try and execute the same script in FF, I get the following error message:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
I've read at numbe of places that if I downgrade the firefox version to 3.6 script will work fine however I am not to keen on downgrading. Can someone please tell me what I am doing wrong?
package hisScripts;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WebdriverTest_1 {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
//driver=new InternetExplorerDriver();
baseUrl = "https://**********/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testUntitled() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.xpath("//a[contains(text(),'my profile')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'about the service')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'contact us')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'help')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'home')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'logout')]")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
The selenium version you are using is extremely old. I don't think firefox 10 is supported in v2.2. The latest is 2.20.
Take a look at change log here. From the notes here native events in firefox 10 were supported starting from v2.19.0 that means you would need 2.19 or higher to support firefox 10.
This problem is due to the compatibility of fire fox version and the selenium jar file version.Use the latest selenium jar files.that can fix the problem.