Waitforpagetoload error? - c#-4.0

In my selenium webdriver code I'm trying to get my page to wait for it to load before it starts finding elements and driving them(entering text into username and password)
I tried using driver.waitforpagetoload(); but it returned this error
Error 1 'OpenQA.Selenium.IWebDriver' does not contain a definition for 'waitforpagetoload' and no extension method 'waitforpagetoload' accepting a first argument of type 'OpenQA.Selenium.IWebDriver' could be found (are you missing a using directive or an assembly reference?)
What type of reference to I need to add?
(coding in c#)

I found it was helpful to use Thread.Sleep(# of milliseconds), which allowed the pages to load before continuing onto the next element.
Example:
using System;
namespace SeleniumTests
{
[TestFixture]
public class FireFoxTests
{
[Test]
public void SomeTest()
{
some code;
Thread.Sleep(2000);
more code;
}
}
}

The error is because webdriver doesn't have a waitForPageToLoad function.
And you dont need it with webdriver because it will automatically block after every action, untill the page loads completely. More details here .. WebDriver FAQ
But you can have custom waits, like wait for Elements to appear on page using WebDriverWait.

Related

Selenium, element not accesible by keyboard [duplicate]

The error is :
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
The code is:
System.setProperty("webdriver.gecko.driver","//Users//rozali//Documents//Selenium//geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
//entering first name
driver.findElement(By.id("u_0_b")).click();
driver.findElement(By.id("u_0_b")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[#id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[#id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[#id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.id("u_0_t")).click();
ElementNotInteractableException: Element is not reachable by keyboard
Element is not reachable by keyboard in plain words means that the element can’t be reached using the keyboard, which means you won't even physically interact with it.
Reason
There can be multiple reasons behind the error Element is not reachable by keyboard which can be either of the following:
The element is hidden, as modern JavaScript-centric UI styles always keep the ugly raw HTML input field hidden. The hidden attribute could have been implemented through either of the following ways:
A temporary overlay of some other element over the desired element.
A permanent overlay of some other element over the desired element.
Presence of attributes e.g. class="ng-hide", style="display: none", etc
As per best practices while sending character sequence, you must not attempt to invoke click() or sendKeys() on any <p> or <div> tag; instead, invoke click() on the desired <input> tag following the Official locator strategies for the webdriver.
Solution
There are different approaches to address this issue.
Incase of temporary overlay, use WebDriverWait inconjunction with ExpectedConditions for the desired element to be visible/clickable as follows:
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.nsg-button"))).click();
Incase of permanent overlay, use executeScript() method from JavascriptExecutor interface as follows:
import org.openqa.selenium.JavascriptExecutor;
String inputText = "Rozmeen";
WebElement myElement = driver.findElement(By.id("u_0_b"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);
You will find a detailed discussion in Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted.
Incase presence of attributes e.g. class="ng-hide", style="display: none", etc., use executeScript() method from the JavascriptExecutor interface to edit and reset the style="display: none" attribute to style="display: block" as follows:
import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("document.getElementById('ID').style.display='block';");
You will find a detailed discussion in Can't fill in the Hidden text area element.
References
For input[type=file], should allow sendKeys even when display=none
Special-casing file upload controls in keyboard-interactability check
Element is not reachable by keyboard
Input field with display: none is not interactable at all?
This particular issue
If you look into the HTML of Facebook login page, the application contains React Native elements. So an element once represented with id as u_0_b in your system may not be represented by the same id as u_0_b in the next run on your system. Hence, we have to take the help of Dynamic Locator Strategy. You can use the following code block to perform your intended steps :
Code Block :
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[#name='firstname' and contains(#class,'inputtext')]")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[#id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[#id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[#id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.xpath("//button[#name='websubmit' and contains(.,'Sign Up')]")).click();
Browser Client :
Update
Addressing the error:
org.openqa.selenium.ElementNotInteractableException: Element is not
reachable by keyboard
has become easier with the availability of Firefox capability moz:webdriverClick
moz:webdriverClick()
Through webdriverClick(), you can pass a boolean value to indicate which kind of interactability checks to run when performing a click or sending keys to an element. For Firefoxen prior to v58.0, some legacy code as imported from an older version of FirefoxDriver was in use. With the availability of Firefox v58, the interactability checks as required by the WebDriver specification are enabled by default. This means that geckodriver will additionally check if an element is obscured by another when clicking and if an element is focusable for sending keys. Because of this change in behaviour, we are aware that some extra errors could be returned. In most cases, the test in question might have to be updated so it conforms with the new checks.
To temporarily disable the WebDriver conformant checks, use false as value for this capability.
Note: This capability exists only temporarily, and it will be removed once the interactability checks have been stabilized.
You can try this code :
public class Rozmeen{
static WebDriver driver;
static WebDriverWait wait;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "F:\\Automation\\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 40);
driver.get("http://www.facebook.com");
//entering first name
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("pagelet_bluebar"))));
driver.findElement(By.name("firstname")).sendKeys("testing it ");
//DOB
selectFromDropDown(driver.findElement(By.name("birthday_day")), "4");
selectFromDropDown(driver.findElement(By.name("birthday_month")), "Jun");
selectFromDropDown(driver.findElement(By.name("birthday_year")), "2013");
//clicking sign up
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("websubmit"))));
driver.findElement(By.name("websubmit")).click();
}
public static void selectFromDropDown(WebElement element , String Visibletext){
Select select = new Select(element);
select.selectByVisibleText(Visibletext);
}
}
try out this code and let me know the status.
In one of the use cases I had the same issue:
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <div id="search"> is not reachable by keyboard
using id for identifying an element before sending keys. Something like:
driver.findElement(By.id("search")).sendKeys("...");
After testing I changed to CSS Selector and it solved the issue:
driver.findElement(By.cssSelector("#search > input:nth-child(2)")).sendKeys("...");
So, I highly recommend to use different methods to interact with the elements, because something else can save your time solving problems.
Sometimes it is also an issue by using name/id like this:
driver.findElement(By.name("phone")).sendKeys("99999999");
Instead of this, use Xpath. This solved the issue for me:
driver.findElement(By.xpath("//*[#id='load_form']/input")).sendKeys("Java");
I got a similar error on a button when the click() operation was performed:
org.openqa.selenium.ElementNotInteractableException Exception
As mentioned by DebanjanB in his answer, the element was not reachable by keyboard.
To solve this, I replaced click() with sendKeys(Keys.ENTER), and the button got clicked.

Using findElement in groovy pages

Apologies if this question seems trivial,.. but I am very very new to groovy/selenium as part of a maven system I’ve been thrown at and am in need to understand what I am missing in trying to get this method to work.
The error I am getting is below:
groovy.lang.MissingMethodException: No signature of method: GebConfig.findElement() is applicable for argument types: (org.openqa.selenium.By$ByName)
I’m in need to locate elements on a web page and would like to use the findElement method, however my code is in groovy as part of step definitions.
I have ended up with the following after lots of attempts but am getting nowhere:
package step_definitions
import features.support.Requests
import geb.*
import org.apache.commons.io.*
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.*
import org.openqa.selenium.remote.*
import cucumber.api.groovy.EN.*
When(~/^find the element named "(.*?)"$/) { String btnName ->
WebElement myElement = driver.findElement(By.name(btnName));
}
I know I can use things like the below for a button and similar for other things like radio buttons and input fields:
browser.$(‘input’, name: ‘btnK’)
$(‘input’, name: ‘btnK’)
But I’d prefer to know how to use the findElement approach.
Any help would be appreciated.
Thanks,
Jim…..
I can see that you are using Geb with Cucumber JVM. If you've setup your environment using geb.binding.BindingUpdater as described in http://gebish.org/manual/current/#writing-your-own-steps then the methods and properties available in your steps are as listed in http://gebish.org/manual/current/#browser-methods-and-properties. You will notice that there is no driver property in that list - if you wish to access the driver instance then you will have to obtain it from browser:
When(~/^find the element named "(.*?)"$/) { String myName ->
WebElement myElement = browser.driver.findElement(By.name(btnName));
}

Loaded SWF's wont preform their functions in air

Back for some help! So I am making an AIR application that loads SWF's into a container to be viewed by the user. However when I load the files into their containers, the SWF's that are loaded are unable to execute their own code. IE press an invisible button on the loaded SWF and it changes colour. I tried to google solutions for this since Security.allowDomain("*"); is throwing this error in flash. However from what I have read, AIR doesn't allow loaded swfs to execute code for some security reason but im not 100% sure on that either.
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
at flash.system::Security$/allowDomain()
at BugFree()[D:\Desktop\BugFree\BugFree.as:72]
Without the Allow domain it throws this security error when attempting to click the invisible button.
*** Security Sandbox Violation ***
SecurityDomain 'file:///D:/Desktop/Rewritten Tester/TechDemoSwordNew.swf'
tried to access incompatible context 'app:/BugFree.swf'
*** Security Sandbox Violation ***
SecurityDomain 'file:///D:/Desktop/Rewritten Tester/TechDemoSwordNew.swf'
tried to access incompatible context 'app:/BugFree.swf'
SecurityError: Error #2047: Security sandbox violation: parent:
file:///D:/Desktop/Rewritten Tester/TechDemoSwordNew.swf cannot access
app:/BugFree.swf.
at flash.display::DisplayObject/get parent()
at TechDemoSwordNew_fla::Button_Play_21/onButtonPress()
This only shows in the Animate output bar. When I publish it, with application with runtime embeded, and open the exe it throws no errors but the invisible button still doesnt work.
Here is the code for the swf being loaded.
btnButton.addEventListener(MouseEvent.CLICK, onButtonPress, false, 0, true);
function onButtonPress(event:MouseEvent):void
{
MovieClip(parent).play();
}
stop();
This is timeline code within the button since that is how the game company who put my item in game did it. I originally submitted it with it all done in classes but that is besides the point. When the button is pressed the loaded SWF should play and then stop. But I get the above mentioned Sandbox violation.
The code used to load the SWF is below
public function WeaponLoad()
{
if(FileMenu.WeaponFileTxt.text != "")
{
LoadWeapon(FileMenu.WeaponFile.nativePath);
}
else if(FileMenu.WeaponFileTxt.text == "")
{
Character.mcChar.weapon.removeChildAt(0);
Character.mcChar.weaponOff.removeChildAt(0);
}
}
public function LoadWeapon(strFilePath: String)
{
WeaponLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, CompleteWeaponLoad);
WeaponLoader.load(new URLRequest(strFilePath), new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain)));
}
public function CompleteWeaponLoad(e: Event)
{
var WeaponClass: Class;
if (MiscMenu.WeaponSelect.MainClick.currentFrame != 3)
{
try
{
trace("WeaponOff");
WeaponClass = WeaponLoader.contentLoaderInfo.applicationDomain.getDefinition(FileMenu.WeaponLinkTxt.text) as Class;
this.Character.mcChar.weapon.removeChildAt(0);
this.Character.mcChar.weaponOff.removeChildAt(0);
this.Character.mcChar.weapon.addChild(new(WeaponClass)());
}
catch (err: Error)
{
trace("Either the weapon class doesnt exist or it is wrong");
this.Character.mcChar.weapon.removeChildAt(0);
this.Character.mcChar.weaponOff.removeChildAt(0);
}
}
else if (MiscMenu.WeaponSelect.MainClick.currentFrame == 3)
{
try
{
WeaponClass = WeaponLoader.contentLoaderInfo.applicationDomain.getDefinition(FileMenu.WeaponLinkTxt.text) as Class;
this.Character.mcChar.weapon.removeChildAt(0);
this.Character.mcChar.weaponOff.removeChildAt(0);
this.Character.mcChar.weapon.addChild(new(WeaponClass)());
this.Character.mcChar.weaponOff.addChild(new(WeaponClass)());
}
catch (err: Error)
{
trace("Either the weapon class doesnt exist or it is wrong");
this.Character.mcChar.weapon.removeChildAt(0);
this.Character.mcChar.weaponOff.removeChildAt(0);
}
}
}
Any help would be apreciated since I have no idea how to change any security sandbox settings within the publish settings since it is greyed out for me. Like I said I tried googling it but I couldn't seem to come up with any answers. Also worth noting is im a self taught novice and I do not know a lot of things in regards to AS3. I know my codes could be cleaner and I plan to clean it up and properly reduce memory consumption once I have the base program up and running. Thank you for the help!
It seems that you're not setting the application domain properly. Here is the code included in as3 documentation:
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("[file path].swf");
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
loader.load(url, loaderContext);
Use it in your LoadWeapon function.
In the meantime try not to use Uppercase letters for starting variables and method names. In ActionScript names starting with Uppercase represent Class names. It will widely improve readability of your code.
Can't you bundle your swfs with the AIR app and use File class to load them? If you want to use classes from the swfs, maybe consider making swc library?

Geb drive method

I'm trying to learn how to use Geb and I'm getting an error. Could you guys help me out?
I'm trying to use the drive method but it is not working. I've tested a few of the other Browser's methods and they work all right. Just the drive method is giving me trouble.
I've checked the API and googled around but didn't find anything helpful. The strange thing is the fact that I don't get an error message. There is no Exception. I'm running the code on Groovy's console and Firefox just chills for a while and then the execution finishes.
Geb 0.9.2, FirefoxDriver and JDK 7
import org.openqa.selenium.WebDriver;
import geb.Browser
import org.openqa.selenium.firefox.FirefoxDriver
public class MyTest {
Browser browser;
void test(){
browser = new Browser(driver: new FirefoxDriver())
browser.go "http://www.google.com" // this works
browser.$("div button", name: "btnK").text() == "Google Search" // this works
browser.drive { // WHY U NO WORK?!!
go "http://www.google.com"
}
}
}
x = MyTest()
x.test()
You should know that drive() is a static method and it's designed to be used in scripts where you don't instantiate a browser instance. You have to decide - you either use a browser instance or the Browser.drive {} method. Yo cannot do both.
You might also consider using one of the integrations with testing frameworks - by doing so you'll get Geb to manage a browser instance for you.

Xceed WPF PropertyGrid : decorating property with Category : compiler error

I have basically the same question as the one I asked here. Adding the using Xceed.Wpf.Toolkit.PropertyGrid.Attributes directive solved that.
This time, the compiler does not like [Category("Shipping")] decoration.
[Category("Shipping")]
public string ShipAddress { get; set; }
How can I deduce or determine what namespace needs to be included when I run into obstacles like this?
Here are the using directives I've included already:
using Xceed.Wpf.Toolkit.PropertyGrid;
using Xceed.Wpf.Toolkit.PropertyGrid.Editors;
using Xceed.Wpf.Toolkit.PropertyGrid.Commands;
using Xceed.Wpf.Toolkit.PropertyGrid.Converters;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
The xaml is this:
<xctk:PropertyGrid AutoGenerateProperties="True" Name="XPG1" IsCategorized="True" />
I know this is an older question, but since it's unanswered I thought it would be helpful to provide one anyway. In this case you need the following using statement:
using System.ComponentModel;
In general, the best way to figure out what namespace or using statement you need is to look for the name of the attribute in the Object Browser under the Xceed namespace, and if you can't find it there, on Google.
One thing to remember - while it shows up as just [Category] in code, the actual name of the class will be CategoryAttribute.

Resources