WebDriverBackedSelenium -getElementTagName execution failed error - selenium

Iam Using WebDriverBackedSelenium and tyring to run my RC cases,i get following error,
Error :
com.thoughtworks.selenium.SeleniumException: getElementTagName execution failed; Element does not exist in cache Backtrace: 0x43f80e 0x4320ae 0x4327e1 0x4336dc 0x4347ba 0x4250e9 0x42ca6c 0x41a597 0x484df8 0x4861f2 0x486491 start_thread [0x7f615369dd8c] 0x7f6150cde04d (WARNING: The server did not provide any stacktrace information); duration or timeout: 25 milliseconds Build info: version: '2.6.0', revision: '13840', time: '2011-09-13 14:55:30' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.38-10-generic', java.version: '1.6.0_22' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:42)
Code i used :
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Selenium selenium = null;
capabilities.setCapability("chrome.binary", "/opt/google/chrome/google-chrome");
WebDriver driver = new ChromeDriver(capabilities);
selenium = new WebDriverBackedSelenium(driver,getCurrentSetupURL());
selenium.type("id","value") - in this line error is thrown!

you have to specify what ID you want to write in. Assume you try to login the user. So in most cases the login page HTML will look like this:
<input type="text" id="username"></input>
<input type="password" id="password"></input>
In order to fill these in, the commands look like this:
selenium.type("id=username", "username");
selenium.type("id=password", "password");
The above code will enter value username into username field and value password into password field
If you never specified what id and value in your code mean, then obvipously you get nullpointerException

Related

Selenium throws weird error on changing to new tab

I have a weird error throwing up while switching tab using selenium web driver.
here is the code that throws the error
var tabs = WebDriver.WindowHandles;
WebDriver.SwitchTo().Window(tabs[tabs.Count - 1]);
This code just switch to a newly open tab. but it fails when with this
invalid argument: 'handle' must be a string
(Session info: chrome=75.0.3770.80)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-
14T08:25:53'
System info: host: 'DESKTOP-9QCDGLU', ip: '10.194.143.155', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: unknown
The passed value .Window() is a string but the error tells that the argument is invalid.
As long as you are using the same window that webdriver opened you shouldn't need to switch. You may try to switch to the window again after the redirect.
Save you window handle:
String myWindowHandle = driver.getWindowHandle();
redirect to the page you want and then call switchTo using the window handle:
driver.switchTo().window(myWindowHandle );
Does your page contain any frames? It may also be possible that you are not in the correct frame after the redirect.

Safari Browser: Switch to frame is not working

I am trying to run few test on Mobile Emulators (Safari Browser) and stuck at a problem. Where after switching to an Iframe I am not able to do any action.
There is already a closed issue for that, however I didn't find any solution after going though this thread.
https://github.com/appium/appium/issues/5832
Code which is causing issue
public PaymentPage fillCreditCardInformation(String cardNumber, String expiryDate, String cvv, String postal ){
switchToPaymentFrame();
WebElement cardNumberEditbox = driver.findElement(By.name("cardnumber"));
}
private void switchToPaymentFrame() {
WebElement frame = driver.findElement(By.name("__privateStripeFrame3"));
driver.switchTo().frame(frame);
}
Emulator Used: Iphone 6s, IPad Mini
Webdriver Version: 3.4.0
Safari Driver: 2.48
Stacktrace:
org.openqa.selenium.WebDriverException: undefined is not an object
(evaluating 'a.querySelectorAll') (WARNING: The server did not provide
any stacktrace information) Command duration or timeout: 30.48 seconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'DL0019', ip: '127.0.1.1', os.name: 'Linux',
os.arch: 'amd64', os.version: '4.4.0-96-generic', java.version:
'1.8.0_131' Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{noReset=true, safari=true,
browserstack.tunnelIdentifier=, browserstack.asyncStop=true,
language=Apache-HttpClient/4.5.3 (Java/1.8.0_131),
browserstack.selenium_version=3.4.0, deviceName==iPad Retina (9.1)
[556DF534-C4AE-48B6-8ED3-BAF86198074A], platform=MAC,
browserstack.video.disableWaterMark=true, desired={noReset=true,
browserstack.tunnelIdentifier=, browserstack.asyncStop=true,
language=Apache-HttpClient/4.5.3 (Java/1.8.0_131),
browserstack.selenium_version=3.4.0, deviceName==iPad Retina (9.1)
[556DF534-C4AE-48B6-8ED3-BAF86198074A], platform=MAC,
browserstack.video.disableWaterMark=true, acceptSslCerts=false,
newCommandTimeout=300.0, browser=ipad, platformVersion=9.1,
acceptSslCert=false, browserName=safari, platformName=iOS,
64bit=false, browserstack.debug=true, orientation=portrait,
browserstack.ie.noFlash=false, os_version=,
mobile={"browser":"tablet","version":"iPad Mini 4-9.1"},
browserstack.geckodriver=0.16.0, version=, browserstack.video=true,
safariIgnoreFraudWarning=true, orig_os=macelc, realMobile=false,
deviceOrientation=PORTRAIT, device=iPad Retina, proxy_type=node},
acceptSslCerts=false, newCommandTimeout=300.0, browser=ipad,
platformVersion=9.1, webStorageEnabled=false, acceptSslCert=false,
browserName=safari, takesScreenshot=true, javascriptEnabled=true,
platformName=iOS, 64bit=false, browserstack.debug=true,
networkConnectionEnabled=false, orientation=portrait,
browserstack.ie.noFlash=false, warnings={}, os_version=,
mobile={"browser":"tablet","version":"iPad Mini 4-9.1"},
browserstack.geckodriver=0.16.0, databaseEnabled=false, version=,
browserstack.video=true, safariIgnoreFraudWarning=true,
orig_os=macelc, realMobile=false, locationContextEnabled=false,
deviceOrientation=PORTRAIT, device=iPad Retina, proxy_type=node}]
Session ID: 6bf643515813d0ccbe5fe75300ac2d8ea15a5960
*** Element info: {Using=name, value=cardnumber}
Can you try this:
Change:
private void switchToPaymentFrame() {
WebElement frame = driver.findElement(By.name("__privateStripeFrame3"));
driver.switchTo().frame(frame);
}
To:
private void switchToPaymentFrame() {
WebDriverWait wait1 = new WebDriverWait(driver, 10);
wait1.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("__privateStripeFrame3")));
}
Seems to me like a known issue.
Simply doesn't work.
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/7658

Difficult to run the script in selenium webdriver which contains HtmlUnitDriver

I am unable to run the basic selenium script which contains the HtmlUnitDriver. If I try to run the code I get the following error.
Code:
public class SampleUnitDriver
{
public static void main(String[] args) throws Exception
{
HtmlUnitDriver unitDriver = new HtmlUnitDriver();
unitDriver.get("http://google.com");
System.out.println("Title of the page is -> " + unitDriver.getTitle());
Thread.sleep(3000L);
WebElement searchBox = unitDriver.findElement(By.className("gsfi"));
searchBox.sendKeys("Selenium");
WebElement button = unitDriver.findElement(By.name("gbqfba"));
button.click();
System.out.println("Title of the page is -> " + unitDriver.getTitle());
}
}
Error:
Title of the page is -> Google
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Returned node was not a DOM element
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'user-PC', ip: '192.168.1.52', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51'
Driver info: driver.version: SampleUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByCssSelector(HtmlUnitDriver.java:1060)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByClassName(HtmlUnitDriver.java:1032)
at org.openqa.selenium.By$ByClassName.findElement(By.java:391)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1725)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1721)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1367)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1721)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:606)
at com.digitalmqc.automation.action.SampleUnitDriver.main(SampleUnitDriver.java:16)
The class name gsfi of the input box is generated by javascript so you have 2 options:
Easy One: Just select it by using the id lst-ib
Better One: Wait for the element to be fully interactive. The reason behind this one being better is that you are trying to input text into the box which javascript plays a role. The former option may throw some unexpected errors.

cucumber jvm selenium example

I am using standart exsample:
cucumber-jvm-selenium-example
When I run test:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.michalvich.cucumber.selenium.example.GoogleSearchTest
Feature: Search on Google
As an user
I want to search on Google
So that I can see results
Scenario: results are shown # com\michalvich\cucumber\selenium\example\GoogleSearch.feature:6
Given the page is open "http://www.google.com" # GoogleSearchScenario.the_page_is_open(String)
[1A Given the page is open "http://www.google.com" # GoogleSearchScenario.the_page_is_open(String)
When I search for "Cucumber" # GoogleSearchScenario.I_search_for(String)
[1A When I search for "Cucumber" # GoogleSearchScenario.I_search_for(String)
org.openqa.selenium.NoSuchElementException: Unable to locate element with name: q
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 15:53:30'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:749)
at org.openqa.selenium.By$ByName.findElement(By.java:292)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1247)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1244)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:987)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1244)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:393)
at com.michalvich.cucumber.selenium.example.GoogleSearchScenario.I_search_for(GoogleSearchScenario.java:26)
at ?.When I search for "Cucumber"(com\michalvich\cucumber\selenium\example\GoogleSearch.feature:8)
But if I change driver:
System.setProperty("webdriver.chrome.driver", "path\\to\\chromedriver.exe");
driver = new ChromeDriver();
It works.
You need to wait for Google ajax to refresh, otherwise you will only have Google return as the page title
#When("^I search for \"([^\"]*)\"$")
public void I_search_for(String search) throws Throwable {
WebElement element = driver.findElement(By.name("q"));
element.sendKeys(search);
element.submit();
// Google ajax wait for 5 seconds
long end = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < end) {
WebElement resultsDiv = driver.findElement(By.className("gssb_e"));
// If results have been returned, the results are displayed in a drop down.
if (resultsDiv.isDisplayed()) {
break;
}
}
}

Selenium 2 RemoteWebDriver -StaleElementReferenceException: Element specified by 'id' is no longer valid

I'm using the 2.4.0 selenium server in hub mode with two nodes each with 5 instances of Internet explorer (IE8 on win7) - this is all running on the same Win7 machine
The following code throws the exception on the final call to FindElements on the RemoteWebDriver
_driver.Navigate().GoToUrl(#"http://devrsql714/webpages/parentview.aspx");
var wait = new WebDriverWait(_driver, new TimeSpan(0, 0, 40));
wait.Until(d => d.FindElement(By.ClassName("TitleAlternative")));
Console.WriteLine(string.Format("Window title: {0}", _driver.Title));
var element = _driver.FindElementById("txtLessonID");
element.SendKeys("13814");
var button = _driver.FindElementById("btnLessonID");
button.Click();
wait = new WebDriverWait(_driver, new TimeSpan(0, 0, 40));
var link = wait.Until(d => d.Title.Contains("01652-06-A"));
Console.WriteLine(string.Format("Window title: {0}", _driver.Title));
Assert.IsTrue(_driver.Title.Contains("01652"));
Console.WriteLine(string.Format("page source: {0}", _driver.PageSource));
_driver.FindElementsByTagName("DIV");
I can see the browser load, navigate, fillin the text box and click the button - the page refreshes the title changes - the assert passes (this is running in MbUnit with Gallio)
but the subsequent call to _driver.FindElementsByTagName throws the exception below - I added waits in case that was the issue and any find elements results in the same exception
what am I doing wrong? - other properties on the driver work such as title and page source (which has the excepted content)
Note the same code but swapping the RemoteWebDriver for a local InternetExplorerDriver does not throw the exception
In both cases capabilities were set to ignore protect mode:
DesiredCapabilities capabilities = DesiredCapabilities.InternetExplorer();
capabilities.Platform = new Platform(PlatformType.Any);
capabilities.SetCapability("ignoreProtectedModeSettings", true);
Execute
OpenQA.Selenium.StaleElementReferenceException: Element specified by 'id' is no longer valid (WARNING: The server did not provide any stacktrace information)
Build info: version: '2.4.0', revision: '13337', time: '2011-08-12 09:57:13'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_20'
Driver info: driver.version: RemoteWebDriver
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 948
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(DriverCommand driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 805
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElements(String mechanism, String value) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 851
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementsByTagName(String tagName) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 622
at SeleniumTests.DemoTest.AnotherTest()
This is apparently a bug in version 2.4.0 of the selenium server. Downgrading to 2.3.0 might make the problem go away. See this thread on the selenium-users mailing list for more information.