Also some text to make stackoverflow allow me to post this sadkjghalksjdblkasnfblkjsfhavlkjdhaflkjansdgkjabslvknacdjlhasd;lfkhasojhgabsd;lvscogkansd;lfiyojgf;cl znxcgiuaerpagisdj;cvljahdfoiaguhsdf[lahdsisudzfgpasdhgoiuaefhblka;gkjahfg
My code:
package packege;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args){
WebDriver driver = new ChromeDriver();
driver.get("https://hordes.io/players");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("console.log(\"Hello Console!\")");
LogEntries entry = driver.manage().logs().get(LogType.BROWSER);
List<LogEntry> logs= entry.getAll();
System.out.println("Logs:");
for(LogEntry e: logs)
{
System.out.println("Message is: " +e.getMessage());
System.out.println("Level is: " +e.getLevel());
}
}
}
Console:
Output of my code:
Please tell me what is wrong? I am doing the same things as in guides.
Edit: I noticed that it caught error messages but not mine... Interesting.
Related
I'm trying to automate a app to do everything that you would have to do by hand. My main goal right now is to get it to click a button after logging into the app.
This is the very last line of code in my IDE
driver.findElement(By.id("com.offerup:id/main_text")).click();
After this line of code executes, OfferUp, the app that I'm testing on, closes. There are no failures in console but, I don't want it to close after that line of code executes.
When I log into the app without running my code, the app stays open but, when I run my code, it closes after driver.findElement(By.id("com.offerup:id/main_text")).click(); is executed.
Why this is happening?
Here is my full code -
package OpenOfferUpTest;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.server.handler.FindElement;
import org.testng.annotations.Test;
import org.testng.annotations.*;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class OpenOfferUp {
AndroidDriver driver;
#Test
public void OpensOfferUp() throws MalformedURLException
{
File OfferUp = new File("C:\\Users\\boung\\Desktop\\OfferUp.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "Virtual Device");
cap.setCapability("platformName", "android");
cap.setCapability("null", "OfferUp");
cap.setCapability("appPackage", "com.offerup");
cap.setCapability("appActivity", "com.offerup.android.login.splash.LoginSplashActivity");
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), cap);
}
#Test
public void SimpleTest() throws InterruptedException {
driver.findElement(By.id("com.offerup:id/email_button")).click();
By path = By.xpath("//*[#text='Enter your email address']");
driver.findElement(path).sendKeys("sourgta#gmail.com");
driver.findElement(By.id("com.offerup:id/next_button")).click();
By path1 = By.xpath("//*[#text='']");
driver.findElement(path1).sendKeys("12manytimes");
driver.findElement(By.id("com.offerup:id/main_text")).click();
}
}
I am new to selenium and java and trying to build a program and facing multiple issues. Listed is the code below for Parent Class.
Login Method error.
Void is an valid type error on Syntax error on token "(".
Even though i tried to change, still i face an error
package MyfirstMavenProject.Myfirstgmailtest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginClass {
//Open the Browser
public void BrowserOpen (String args[]) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
//Get the URL
driver.navigate().to("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Identifies the gmail and password
public void Login (String args[]) {
WebElement emailfield = driver.findElement(By.id("Email"));
emailfield.sendKeys("abc.com");
driver.findElement(By.id("next")).click();
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#type='password']"))).sendKeys("abc");
driver.findElement(By.id("signIn")).click();
}
}
}
Child Class is where i am getting error on argument. Need info as to what argument should i pass. I am trying to use the Login method created in the above class
package MyfirstMavenProject.Myfirstgmailtest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ComposeEmailClass extends LoginClass {
//Method to identify the compose email
public void ComposeEmail (String args[]){
WebDriver ComposeEmail = new FirefoxDriver();
ComposeEmail.findElement(By.className("T-I J-J5-Ji T-I-KE L3")).click();
}` public static void main (String args[]){
ComposeEmailClass ClickCompose = new ComposeEmailClass();
ClickCompose.Login(args);`\\Need more info`
ClickCompose.ComposeEmail(args);
}FireFox.Quit;
}
Use following code:
There are lots of syntax error present in your code.
Login Class: Corrected
package MyfirstMavenProject.Myfirstgmailtest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginClass
{
WebDriver driver =null;
//Open the Browser
public void BrowserOpen (String args[])
{
driver = new FirefoxDriver();
driver.manage().window().maximize();
//Get the URL
driver.navigate().to("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
//Identifies the gmail and password
public void Login (String args[])
{
WebElement emailfield = driver.findElement(By.id("Email"));
emailfield.sendKeys("youremail#gmail.com");
driver.findElement(By.id("next")).click();
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//* [#type='password']"))).sendKeys("password");
driver.findElement(By.id("signIn")).click();
}
}
ComposeEmailClass: Corrected
package MyfirstMavenProject.Myfirstgmailtest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ComposeEmailClass extends LoginClass
{
//Method to identify the compose email
public void ComposeEmail(String args[])
{
WebDriver ComposeEmail = new FirefoxDriver();
ComposeEmail.findElement(By.className("T-I J-J5-Ji T-I-KE L3")).click();
}
public static void main(String args[])
{
ComposeEmailClass ClickCompose = new ComposeEmailClass();
ClickCompose.BrowserOpen(args);
ClickCompose.Login(args);
ClickCompose.ComposeEmail(args);
}
}
You have to Call ClickCompose.BrowserOpen(args); before ClickCompose.Login(args);
and String[] args is not required in your method declaration .
Below code has an error is at the setup location.Why is this error coming up?? .The error is as follow:
There is an error in the public void Setup().
The error is The method Setup() is undefined for the type jammytestappium.
This was causing harm while executing the code.
My code looks as follows:
package com.example.jamappium;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Driver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.server.handler.FindElement;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.sun.jna.platform.win32.SetupApi;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
public class Jammytestappium {
{
AndroidDriver<WebElement> abcd;
#BeforeClass
public void setup()
{
DesiredCapabilities test=new DesiredCapabilities();
test.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,
"com.veronicapps.veronica.simplecalculator");
test.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,
"com.veronicapps.veronica.simplecalculator.MainActivity");
test.setCapability(MobileCapabilityType.VERSION, "4.2.2");
test.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator");
abcd = (AndroidDriver) new RemoteWebDriver(new URL(
"http://127.0.0.1:4723/wd/hub"),test);
}
}
Try removing the extra braces after "public class jammytestappium {"
package Saradhi;
import java.util.concurrent.TimeUnit;
import org.apache.bcel.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoginAndNavigate {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "E:ChromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://opensource.demo.orangehrmlive.com/");
WebElement frmtime = driver.findElement(By.id("workShift_workHours_from"));
Select se = new Select(frmtime); // error line
I'm getting an error message in the above line.
I have tried importing related packages but still didn't work.
You are importing a wrong package. Try
import org.openqa.selenium.support.ui.Select;
instead of
import org.apache.bcel.generic.Select;
Use this import:
import org.openqa.selenium.support.ui.Select;
And remove this one:
import org.apache.bcel.generic.Select;
I tried importing select class in my program using selenium webdriver,
but I am not able to import the predefined package.
Can anyone please guide me on this?
package com.siri.dev;
import org.apache.bcel.generic.Select;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MyntraTests {
private WebDriver driver;
#Before
public void setup() {
intializedriver("firefox");
}
#Test
public void get() {
driver.get("http://www.myntra.com");
driver=waitForPageLoaded(driver);
driver.manage().window().maximize();
System.out.println("Page opened successfully");
WebElement element = driver.findElement(By.className("tab"));
org.openqa.selenium.support.ui.Select elem = new Select(element);
elem.selectByVisibleText("BIBA");
}
private void intializedriver(String browser) {
// TODO Auto-generated method stub
driver = new FirefoxDriver();
driver.manage().window().maximize();
}
import org.openqa.selenium.support.ui.Select;
Use
Select selectElement = new Select(driver.findElement(By.cssSelector("")));
The reason you are having this
org.openqa.selenium.support.ui.Select elem = new Select(element);
is cause you have imported a wrong class imported already
import org.apache.bcel.generic.Select;
remove that import by deleting it and then
import org.openqa.selenium.support.ui.Select
If you are using Eclipse you can always remove unused imports by ctrl+shift+o.
Select is a class of package org.openqa.selenium.support.ui
So you are supposed to do a import statement as follows:
import org.openqa.selenium.support.ui.Select;
and then you can do your task as:
Select elem = new Select(element);
elem.selectByVisibleText("BIBA");
U have imported a wrong package : import org.apache.bcel.generic.Select;
If you use Maven, you will want to know that packages under org.openqa.selenium.support are in artifact selenium-support. That does not get pulled in along with selenium-api or any of the selenium-*-driver artifacts. You can refer to the Selenium Maven information.