I'm new with using Java, Selenium en the Webdriver
I use: selenium 3 beta3, Java jdk1.8.0_101 and firefox 48.01
Also I use the Geckodriver because that is needed for working with sel3.
I am trying to open a url. Opening the browser is working.
The code I use is below.
package AutomatedScripts;
import org.openqa.selenium.WebDriver; // driver for Webdriver
import org.openqa.selenium.firefox.FirefoxDriver; //driver for Firefox
public class GoogleSearchOneTime {
public static void main(String[] agrs) {
System.setProperty("webdriver.firefox.marionette","C:\\selenium-3.0.0\\geckodriver\\geckodriver.exe");
// Launch a firefox browser
WebDriver driver = new FirefoxDriver();
// go to Google.com
driver.get("http://www.google.com");
// go to google.com
// driver.navigate().to("http://www.google.com");
//Enter search terms
//driver.findElement(By.id("lst-ib")).clear();
//driver.findElement(By.id("lst-ib")).sendKeys("Google");
//Click on the searh button
//driver.findElement(By.name("btnG")).click();
//check page title contacts the search term
}
}
Replace you System.setProperty as below
System.setProperty("webdriver.gecko.driver", "C:\\selenium-3.0.0\\geckodriver\\geckodriver.exe");
Here an example link that you can refer Launching firefox browser using Geckodriver
Related
I am using WebView for loading websites in my project. It is loading websites but very slow. It takes around 10 to 15 seconds to load this site.
I try a solution from this thread. I have added android:hardwareAccelerated="true" on the manifest under application level, but no luck.
For iOS and Windows the solution is below: But I don't know how to create the custom render.
In iOS, try to use WKWebView instead of UIWebView.
For the UWP, use Windows.UI.Xaml.Controls.WebViewcontrol instead of using the built-in Xamarin WebView control.
Can I get the sample custom renderer for iOS and Windows-like above?
It is loading websites but very slow
The speed of loading website will up to lots of causes . For example, it will consume a lot of time if the web contains many remote css/js file . And it will also up to network performance .
The link that you provided loads slow even if on browser on my side . It contains lots of remote css if we check the source code.
For Android , We can create an custom renderer webview to accelerate it.
Set Render Priority to hight.
Enable the dom storeage.
When Loading the html, we can disable the image showing, when
loading finished, load the image by
Control.Settings.BlockNetworkImage.
Enable the Cache, if you load it at the nexttime, you can load it
quickly.
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(MyWebviewRender))]
namespace MyWebviewDemo.Droid
{
public class MyWebviewRender : WebViewRenderer
{
public MyWebviewRender(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
Control.Settings.JavaScriptEnabled = true;
Control.Settings.SetAppCacheEnabled(true);
Control.Settings.CacheMode = Android.Webkit.CacheModes.Normal;
Control.Settings.SetRenderPriority(RenderPriority.High);
Control.Settings.DomStorageEnabled = true;
Control.Settings.BlockNetworkImage = true;
Control.SetWebChromeClient(new MyWebChromeClient());
}
}
internal class MyWebChromeClient : WebChromeClient
{
public override void OnProgressChanged(Android.Webkit.WebView view, int newProgress)
{
base.OnProgressChanged(view, newProgress);
if (newProgress == 100)
{
// webview load success
// // loadDialog.dismiss();
view.Settings.BlockNetworkImage=false;
}
else
{
// webview loading
// loadDialog.show();
}
}
}
}
In iOS, try to use WKWebView instead of UIWebView. For the UWP, use Windows.UI.Xaml.Controls.WebViewcontrol instead of using the built-in Xamarin WebView control.
In your case it will only have less improve even if using above solution . You could add an ActivityIndicator during the loading . If you can access the website , it would be better to download the css file to local and loading them in ContentPage .
I am loading a webpage in jxbrowser in java swing, I want to block or disable right click on that page, I searched but not got the answer, please let me know if any one has any suggestion.
Thanks
After a long search, finally I have a working solution for disabling right click
final Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
view.setMouseEventsHandler(new InputEventsHandler<MouseEvent>() {
#Override
public boolean handle(MouseEvent arg0) {
if(arg0.getButton() == MouseEvent.BUTTON3)
return true;
return false;
}
});
The latest JxBrowser has major API changes. If you are using 7.* or above the approach is as follows.
browser.set(MoveMouseWheelCallback.class, params -> Response.suppress());
Available Callbacks
EnterMouseCallback
ExitMouseCallback
MoveMouseCallback
MoveMouseWheelCallback
PressKeyCallback
PressMouseCallback
ReleaseKeyCallback
ReleaseMouseCallback
TypeKeyCallback
Links
What's New
API Documentation
Not able to click on button element in iframe window, but getting success while debug.
While debugging I am successfully getting passed through action. Both the times(debugging and executing) UI(application) cannot see any actions performed.
Can Any one suggest this please. I have tried using giving waits. Xpath for button can not be wrong as Its successfully getting passed while debugging.
May be it a browser issue or something? I am using firefox browser
waitforelementpresent(locator.login_email);
click(locator.login_email);
type(locator.login_email,email);
click(locator.login_password);
type(locator.login_password,password);
Thread.sleep(5000);
click(locator.login_button); //This button I need to click
Base Class
public static void click(By by) {
WebDriverWait wait = new WebDriverWait(driver, defaultWaitPeriod);
wait.until(ExpectedConditions.elementToBeClickable(by));
driver.findElement(by).click();
}
public static void type(By by, String type) {
WebDriverWait wait = new WebDriverWait(driver, defaultWaitPeriod);
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
driver.findElement(by).clear();
driver.findElement(by).sendKeys(type);
Locators
public By login_email=By.xpath("//input[#placeholder='Email ']");
public By login_password=By.xpath("//input[#placeholder='Password ']");
public By login_button=By.xpath("//form[#class='m-t ng-dirty ng-valid-email ng-valid-parse ng-valid ng-valid-required']//button");
html code
I appreceate any little help I can get on the issue I'm facing with HtmlUnit.
What I need to do is to login to my application, go to the home page and get a list of all links, text fields, buttons, etc., on my home page.
I tried coding this, and here's what I can do.
I can launch the page, find the login controls, enter user id and password and click Login.
The login is successful. At this point, my application displays the home page, which is masked by an iFrame on top, which displays the last login time and other details. There's an OK button on that which I have to click for the underlying home page to be unmasked.
I am able to click the OK button as well.
And now here's what I am unable to do.
Once I click OK, the underlying home page is unmasked, yet my HtmlPage object is empty (not null).
Below is my code.
import java.io.IOException;
import java.net.MalformedURLException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
public class HTMLUnitSample {
public static void main(String args[]){
final WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setPopupBlockerEnabled(false);
try{
//Get the first page
final HtmlPage loginPage = webClient.getPage("http://****:****/****/****");
//Fill up the login form
loginPage.getElementById("USERID").setAttribute("value", "****");
loginPage.getElementById("user_pwd").setAttribute("value","****");
final HtmlForm loginForm = loginPage.getFormByName("frmLogin");
HtmlSubmitInput button = loginForm.getInputByName("submit");
HtmlPage homePage = button.click();
/*
System.out.println("Body - " + homePage.getBody().asText());
System.out.println("No. of Frames in Home Page - " + Inte ger.toString(homePage.getFrames().size()));
System.out.println("Total no. of elements on Home Page - " + Integer.toString(homePage.getElementsByTagName("*").size()));*/
//Click the OK button
HtmlButtonInput okButton = (HtmlButtonInput)homePage.getElementByName("Ok");
HtmlPage homePage2 = okButton.click();
System.out.println(homePage2.asText());
System.out.println("Done");
}
catch(MalformedURLException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
}
The output I get for
System.out.println(homePage2.asText());
is simply an empty string.
I even tried
homePage2.getElementsByTagName("*");
but in vain.
What I need is to actually find the elements on the home page after I click OK.
Please help me. Any little help is greatly appreciated.
In the Flex framework a custom preloader can be used while the site is loading.
In the Adobe docs it specifies that 'the progress bar [preloader] is displayed if less than half of the application is downloaded after 700 milliseconds of downloading.'
However I ALWAYS want the preloader to appear instantly since I know that 95% of our users are first time visitors and the site is over 500kb. I dont want people to have to wait .7 seconds for the preloader animation to appear.
I would think in theory that it is possible to 'monkey patch' the framework to remove this .7 second limitation. I dont have time to figure out how, and I've never done it before.
Anybody help?
You should just extend the DownloadProgressBar, try the following code. i've used this before and I've found jesse warden site click here usful for info on this (where I found out about it and this is a cut down version of his code)
package{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;
public class Preloader extends DownloadProgressBar
{
/**
* The Flash 8 MovieClip embedded as a Class.
*/
[Embed(source="yourPreloaderFile.swf")]
private var FlashPreloaderSymbol:Class;
private var clip:MovieClip;
public function Preloader()
{
super();
clip = new FlashPreloaderSymbol();
addChild(clip);
}
public override function set preloader(preloader:Sprite):void
{
preloader.addEventListener( FlexEvent.INIT_COMPLETE , onFlexInitComplete );
centerPreloader();
}
private function centerPreloader():void
{
x = (stageWidth / 2) - (clip.width / 2);
y = (stageHeight / 2) - (clip.height / 2);
}
private function onFlexInitComplete( event:FlexEvent ):void
{
dispatchEvent( new Event( Event.COMPLETE ) );
}
protected override function showDisplayForDownloading(time : int, event : ProgressEvent) : Boolean {
return true;
}
}
}
after that just change the preloader property in the main application tag to the Preloader class.
This is in mx.preloaders::DownloadProgressBar.as, line 1205 in the showDisplayForDownloading function.
Old school monkey-patching is out with AS3, but you can either edit the Flex source and compile yourself a new framework.swc (apparently a pain), or just include it in your source path (source paths override .swcs); or derive your own preloader class from DownloadProgressBar that just overrides showDisplayForDownloading and returns true.
You can find the framework source in '%PROGRAMFILES%\Adobe\Flex Builder 3[ Plug-in]\sdks\3.0.0\frameworks\projects\framework\src', then the package path. Change the sdk version if you are using 3.1, or whatever.
I'd guess that delay is there for two reasons:
You don't want the preloader to
"blink" in once the page is already
cached
The preloader itself has to
load
When I need to make absolutely sure a preloader is shown instantly I make a small wrapper swf that has just the preloader and load the main swf from there.
its not possible to make preloader show instantly , since some classes needs to be downloaded before progress can be displayed . other alternative can be that you display a progress in html and when flash movie is loaded it shows up but here .