I am trying to run the below code
package JavaBasics;
enter code here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class OpenBrowserURL {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Pooja\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.makemytrip.com/?ccde=us");
}
}
I am getting error java.lang.NoClassDefFoundError for get as the jar files that i downloaded 3.141.59 has get as void
How can i fix this? Is this an issue with the jar files I downloaded. Please advice
Related
//Eclipse java code:
package openbrowser;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class OpenChrome {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "d://chromedriver.exe");
WebDriver driver=new ChromeDriver();
}
}
eclipse error
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Om Murugaa\Downloads\Testing\selenium-server-standalone-3.141.59.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.eclipse.jetty.http.Http1FieldPreEncoder not in module
Adding maven into eclipse resolved this error.
I got the HTML in console using getpagesource in selenium java .
Now i need only the tag 'Forms' in the console result.
How do i do that?
public class Test {
private static final String HTMLPageSourceCode = null;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Selenium project\\chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://''/tandem/login/?");
String pagesource = driver.getPageSource();
System.out.println(pagesource);
}
You can use following code snippet for this :
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
//Sample Java class to fetch list of all tag with tagname forms
public class Test {
public static void main(String[] args) {
String geckoDriverPath=Class1.class.getResource("/firefox/geckodriver.exe").getPath();
System.setProperty("webdriver.gecko.driver",geckoDriverPath);
WebDriver driver = new FirefoxDriver();
driver.get("http://www.URL.com");
List<WebElement>list =driver.findElements(By.tagName("form"));
for(WebElement ele:list) {
System.out.println(ele.getText());
}
}
}
Once you get the lists you can fetch individual form element and perform action like getting text.Hope, this helps
I'm facing errors while trying to execute a simple code to launch a chrome browser and open google.com but not able to launch the browser. Attached is the error message.
This is the code -
package gmailpkg;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class login {
public static String driverPath = "X:/JARs-Setup/chromedriver_win32/";
public static WebDriver driver;
public static void main(String []args) throws InterruptedException {
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver", driverPath+"chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://google.com");
Thread.sleep(2000);
//driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.xpath( "//*[#href='https://mail.google.com/mail/?tab=wm']")).click();
}
}
I have followed exact instructions from the link eclipse-jcde, and now I have all JCDE features in my eclipse (I'm using eclipse ver 4.3.1). I made a new java card project and added new applet file to it, but when I try to run the project it shows below error:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/String
and this is my (empty!) code:
package myPackage;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
public class MyApplet extends Applet {
private MyApplet() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new MyApplet().register();
}
public void process(APDU arg0) throws ISOException {
// TODO Auto-generated method stub
}
}
what should I do?
I created a dynamic web project using Eclipse. I have a few java programs which I placed in the "Java Resources/src" folder. These programs use Lucene libraries which I placed in the "WebContent/WEB-INF/lib" folder. The Java programs need access to a few text files and a directory containing the index files generated by Lucene. I placed these static files under WebContent in eclipse so that they appear in the exported WAR file.
I am accessing these static files by referring to them directly in the Java program.
BufferedReader br = new BufferedReader(new FileReader("abc.txt"));
//abc.txt is in the WebContent folder of Eclipse project.
From the JSP page, I am calling the java program (which contains the above line) but it shows a FileNotFoundException. Please help me regarding this.
You can not access resources available inside webapp directly from Java.
As files from /src/YourClass.java goes under /WEB-INF/classes/ when compiled. So, When you try to access BufferedReader br = new BufferedReader(new FileReader("abc.txt"));.
It searches "abc.txt" at ``/WEB-INF/classes/abc.txt` as per your given example.
Use servletContext.getRealPath("/"); which returns path of your web application's webapps directory and then you can access resources using this path.
Note: The path returned by servletContext.getRealPath("/"); also depends on how you have deployed web application. As by default eclipse used its own internal mechanism to deploy web application.
Here is the sample screenshot on how it should be
Servlet Code:
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StaticTestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ServletContext servletContext;
private String rootPath;
public StaticTestServlet() {
super();
// TODO Auto-generated constructor stub
}
#Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
super.init(config);
servletContext = config.getServletContext();
rootPath = servletContext.getRealPath("/");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("In Get and my path: " + rootPath + "documents"); // documents is the direcotry name for static files
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("In Post and my path: " + rootPath + "documents"); // documents is the direcotry name for static files
}
}