Selenium - Import devtools - selenium

I am capturing network HTTP requests. This technique is discussed here https://applitools.com/blog/selenium-4-chrome-devtools/#h.bc0ghombcetz
When I try to import the selenium class for 'Network', I get several options :
-org.openqa.selenium.devtools.v103.network.Network
-org.openqa.selenium.devtools.v102.network.Network
-org.openqa.selenium.devtools.v101.network.Network
How I could pick a "general" import (without specifying the version) because I dont want to change with each new release the import version? Any ways to do that?

Related

Cannot import kotlin.test.Test with gradle

I use (don't care about versions, I use platform to manage versions):
testCompile("org.jetbrains.kotlin:kotlin-test-testng")
testCompile("org.jetbrains.kotlin:kotlin-test")
testCompile("org.jetbrains.kotlin:kotlin-test-common")
But cannot import kotlin.test.Test:
import kotlin.test.Test
Test shows red in IDEA, means not found, Why? something I ignored?

Trouble with imports in IntelliJ IDEA CE for and FTC Robotics Simulator

I am trying to use the virtual robot simulator designed by team Beta#8397 and got the simulator working. Now I am trying to put my teams code in so that we can test it. I am getting a bunch of errors that I'm pretty sure all stem from one error that some of the imports aren't importing. Also, my teams code builds fine when not combined with the simulator. I'm not amazing a java, but do know how most of my teams code works. Here is the code for the imports
package org.firstinspires.ftc.teamcode.Robovines;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.robot.Robot;
import com.qualcomm.robotcore.util.Hardware;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.util.Range;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DigitalChannel;
The errors are on lines 4,5 and 13 with the package being the first line. On line 4 the error is that com.qualcomm.robotcore.robot.Robot does not exist. On lines 5 and 13 the error is that symbol "Hardware" and "DigitalChannel" respectively cannot be found.
Here is the whole project
#BookNinja S : The link you provided doesn't take me to your code.
The virtual robot simulator provides a subset of the functionality of the FTC SDK.
That subset has increased over time, but as commented by #CrazyCoder, the Controller module does not include the com.qualcomm.robotcore.robot.Robot, com.qualcomm.robotcore.util.Hardware, or com.qualcomm.robotcore.hardware.DigitalChannel classes.
With regard to DigitalChannel, this type of sensor is not part of the virtual robot functionality. But, it would be easy to add a dummy DigitalChannel class to the controller (so, getState would always return false, and setState would do nothing).
Dummy classes could probably be used for Hardware and Robot as well, but that would depend upon how you are using those classes in your op modes.
If you submit this as an issue on the virtual_robot github repository, with a link to your project or an explanation of how you are using the Hardware and Robot classes, we (ftc team Beta 8397) can probably add the needed functionality to the virtual_robot project.

FileUtils not showing suggestion to import predefined class for Screenshot functionality in selenium WebDriver

I am not allowed to use FileUtils in the program and error is shown when doing so. Even no suggestion is showing to import this pre-defined Class. I tried to search the solution but what I found was to import the class. But in my case even suggestion is not showing to import any class. Hovering on the "FileUtils" shows the suggestion to create FileUtils class/interface. Below is my code:
package captureScreenshot;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils; //Getting Error at this line
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import com.google.common.io.Files;
public class FacebookScreenshot {
#Test
public void captureScreenshot() throws IOException
{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[#name='firstname']")).sendKeys("Anil Kumar");
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyfile(source,new File("./Screenshots/facebook.png")); //Getting error at this line
driver.quit();
}
}
FileUtils Class
FileUtils Class is defined in org.apache.commons.io.FileUtils which provides the general file manipulation utilities in the following areas :
writing to a file
reading from a file
make a directory including parent directories
copying files and directories
deleting files and directories
converting to and from a URL
listing files and directories by filter and extension
comparing file content
file last changed date
calculating a checksum
org.apache.commons.io is bundled along with selenium-server-standalone-x.y.z by default and available ready to use.
But the behavior you are observing is pretty much inline with your usecase where you mentioned that you are not allowed to use FileUtils in the program. It can be either of the scenarios as mentioned below :
Incase you are using JARs from selenium-java-3.9.1 client, the JAR containing org.apache.commons.io is not being added to your project.
Incase you are using Maven with selenium-java-3.9.1 client dependency the modules containing FileUtils Class have been excluded.
For the following above mentioned reasons, when you mention FileUtils in your program it doesn't show any suggestion to import the class. Moreover if you forcefully provide the import, it will show error on that line.
The line FileUtils.copyFile(); has been updated to FileHandler.copy()
Yes with Selenium Latest version we should use FileHandler.copy()
It works and doesn't throw any error.
// Take Screenshots example
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileHandler.copy(scrFile, new File("<your path>\\screenshot.png"));
download maven commons-io jars from: https://mvnrepository.com/artifact/commons-io/commons-io
and add jars to your build Path in your project
In the above FileHandler.copy(scrFile, new File("\screenshot.png"));
here copy -the method copy(File, File) is undefined for the type FileHandler is occured

Unable to invoke compose screen in Gmail/Yahoomail using selenium

Can some one help me out how can i invoke compose screen in Gmail/Yahoomail using selenium commands.
Tried with the following commands.
selenium.click("href=compose link");
selenium.click("name=Compose");
you can use webdriver and easily can invoke compose mail screen from gmail/yahoo.
See the code below:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import selenium.webdriver.support.ui as ui
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re, os
import HTMLTestRunner
import xlrd
class gmail(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://gmail.com"
self.verificationErrors = []
def test_gmail_login(self):
driver=self.driver
driver.get(self.base_url +"/")
driver.find_element_by_xpath("//*[#id='Email']").clear()
print "1. enter user name in username text field"
driver.find_element_by_xpath("//*[#id='Email']").send_keys("xxxx")
driver.find_element_by_xpath(".//*[#id='Passwd']").clear()
print "2.enter password in password text field"
driver.find_element_by_xpath(".//*[#id='Passwd']").send_keys("xxxx")
print " 3. Click signIn button. it has redirect to corresponding gmail home page"
driver.find_element_by_xpath("//*[#id='signIn']").click()
print "click compose mail button"
driver.find_element_by_xpath("//*[#id=':b7']/div/div").click()
driver.save_screenshot('/compose.png')
try:
driver.find_element_by_xpath("//*[#class='z0']/div").click()
`
You can easily achieve this by using Selenium IDE. Just record the whole scenario in the SIDE and do the below steps
1. GoTo Options
2. Format
3. Click the Java/ Junit4/ Remote Control option.
Now you can see the exact Selenium RC code for the scenario you did and copy and paste it in to any IDE and make use of it.
One advisable suggestion, selenium RC is deprecated and there is no further development on RC. The future is on Selenium WebDriver. Please incorporate in to WebDriver.
Edited:
Try this code:
//Assume driver is initialized properly some where else.
driver.get("http://www.gmail.com/");
driver.findElement(By.id("Email")).clear();
driver.findElement(By.id("Email")).sendKeys("UserName");
driver.findElement(By.id("Passwd")).clear();
driver.findElement(By.id("Passwd")).sendKeys("Password");
driver.findElement(By.id("signIn")).click();
//Add some wait. Use Selenium Implicit wait and Explicit wait.
Thread.sleep(5000);
driver.findElement(By.xpath("//div[2]/div/div/div/div[2]/div/div/div/div/div")).click();
driver.findElement(By.id("gbi4t")).click();
driver.findElement(By.id("gb_71")).click();
It may help you.
SIDE Screen shot:
To invoke Compose screen of Gmail in Selenium-RC using Java as below:
selenium.click("//div[text()='COMPOSE']");
To invoke Compose screen of Yahoomail in Selenium-RC using Java as below:
selenium.click("id=global_compose_top");
The following is the Selenium WebDriver Java code for gmail:
driver.findElement(By.xpath("//div[text()='COMPOSE']")).click();
The following is the Selenium WebDriver Java code for yahoo mail:
driver.findElement(By.id("global_compose_top")).click();
Use selenium wrbdriver
http://ngowda.blogspot.in/2014/01/uploading-file-in-e-commerce-site-using.html
here full code of compose a mail in gmail

Selenium/Python:TypeError:undound method get()

I'm a new in Python with Selenium. I tried to test my first python/selenium code and got an error.
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import time
# Create a new instance of the Firefox driver
driver = webdriver.Firefox
# go to the google home page
driver.get("http://www.google.com")
Here, I've got the error:
**TypeError:unbound method get() must be called with Webdriver instance as first argument (got str instance instead)**
Anybody knows how to tackle this issue?
Thanks in advance!
You need () after webdriver.Firefox to actually call the class's constructor and create an instance.