Selenium webdriver: What is the substitute for browserbot? - selenium

I'm trying to convert some Selenium HTML tests to use the WebDriver 2.0 framework. According to the web site (http://seleniumhq.org/docs/03_webdriver.html), the WebDriver framework no longer supports the "browserbot" Javascript variable. So my question is, how do I convert a command like
<tr>
<td>verifyEval</td>
<td>this.browserbot.getUserWindow().s.pageName</td>
<td>Config_6_Summary_Confirm_EX</td>
</tr>
using WebDriver? When I run the command
String target = selenium.getEval("this.browserbot.getUserWindow().s.pageName")
commnand, I get an exception stating, "this.browserbot is undefined". Thanks, - Dave

I make a suggestion to following.
String target = selenium.getEval("window.s.pageName")
You can access to 'browserbot' from WebDriver's getEval by "selenium.browserbot".(not "this")
selenium.getEval("typeof(this.browserbot)"); // undefined
selenium.getEval("typeof(selenium.browserbot)"); // object
but, can not use some browserbot function.
(I don't know the deference of 'enabled function' and 'disabled function'. sorry)
"getUserWindow()" is disabled.
You can use a "window" instead of it.

Related

While opening Gmail, following error occurs- Expected [object Undefined] undefined to be a string

Expected [object Undefined] undefined to be a string,
The code I am using is following:
System.setProperty("webdriver.gecko.driver","E:\\Software\\geckodriver-
v0.16.1-win64\\geckodriver.exe");
WebDriver wd= new FirefoxDriver();
wd.get("https://www.google.co.in/");
//wd.findElement(By.xpath(".//*
[#id='gbw']/div/div/div[1]/div[1]/a")).click();
wd.findElement(By.linkText("Gmail")).click();
WebElement e1= wd.findElement(By.xpath("//input[#id='identifierId']"));
e1.sendKeys("abc#gmail.com");
wd.findElement(By.xpath("//div[#id='identifierNext']/content/span[text()='Ne
xt']")).click();
error log
error log
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:41)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:204)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:104)
at register_prctc.gmail.main(gmail.java:15)
Here is the solution to your Question:
To work with Selenium 3.4.0, geckodriver v0.16.1 & latest Mozilla Firefox 53.x you need to set the absolute path of the geckodriver in your code as:
System.setProperty("webdriver.gecko.driver","C:\\your_dir\\geckodriver.exe");
As per best practices you should not use Thread.sleep(6000), instead use ImplicitlyWait or ExplicitWait.
The xpath .//[#id='gbw']/div/div/div[1]/div[1]/a you used doesn't identifies any unique element. To find the element Gmail link you can use the linkText locator as:
wd.findElement(By.linkText("Gmail")).click();
For sending text into Email or Phone field provide a unique xpath as:
WebElement e1= wd.findElement(By.xpath("//input[#id='identifierId']"));
The xpath to click on Next button looks vulnerable to me, you may like to change it to : wd.findElement(By.xpath("//div[#id='identifierNext']/content/span[text()='Next']")).click();
Here is the working set of your own code with some simple tweaks:
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
WebDriver wd= new FirefoxDriver();
wd.get("https://www.google.co.in/");
wd.findElement(By.linkText("Gmail")).click();
WebElement e1= wd.findElement(By.xpath("//input[#id='identifierId']"));
e1.sendKeys("id#gmail.com");
wd.findElement(By.xpath("//div[#id='identifierNext']/content/span[text()='Next']")).click();
Let me know if this Answers your Question.
Remove Selenium-java-2.53.1.jar file and update all jars

JSONOBject hash not found

I am working on Test Automation Script using JAVA and Selenium WebDriver ,
My test is running on cloud environment (crossbrowsertesting.com).
There is an feature to take snapshots of browser window ,
When I was using RemoteWebDriver this line of code work fine , but need to replace it with WebDriver because reason not bale to get windowHandles.
But I am getting following error now , stating
"The method getSessionId() is undefined for the type WebDriver"
snapshotHash=myTest.takeSnapshot(driver.getSessionId().toString());
//takeSnapshot method :
public String takeSnapshot(String seleniumTestId) throws UnirestException {
System.out.println("Screen Shots Taken.");
/*
* Takes a snapshot of the screen for the specified test.
* The output of this function can be used as a parameter for setDescription()
*/
HttpResponse<JsonNode> response = Unirest.post("http://crossbrowsertesting.com/api/v3/selenium/{seleniumTestId}/snapshots")
.basicAuth(username, api_key)
.routeParam("seleniumTestId", seleniumTestId)
.asJson();
// grab out the snapshot "hash" from the response
snapshotHash = (String) response.getBody().getObject().get("hash");
return snapshotHash;
}
I dont quite understand why you need to use "WebDriver" in place of "RemoteWebDriver" ? "RemoteWebDriver" is the mother of all web driver implementations and it should be good enough to work with any remote grid environment. I dont understand why you need to switch to using "WebDriver" reference which is one of the interfaces that "RemoteWebDriver" implements. getSessionId() is NOT part of any interface specifications but its a direct implementation that RemoteWebDriver provides.
getWindowHandles() is part of WebDriver interface specification and you should still be able to use it.

behat mink equivalent of dropdown->selectOptionByText()?

I'm working with Selenium and behat mink for the first time. I have the following code:
$category_dropdown = $this->find('xpath', "//select[#name=\"category\"]");
echo $category_dropdown->getHtml();
$category->selectOptionByText('Take Out);
and the output is:
<option value="183">Fast Food</option>
<option value="186">Take Out</option>
PHP Fatal error: Call to undefined method Behat\Mink\Element\NodeElement::selectOptionByText()
The line $category->selectOptionByText('Take Out'); causes errors because the function selectOptionByText doesn't actually exist. Is there another way to achieve the intended behaviour?
I'm so new to all this that I'm still trying to figure out the online documentation for this framework.
You were close...
Try to use
$category->selectOption('Take Out');
Here is the LINK to all the methods from NodeElement class
And by the way there is already Gherkin method which can help you
I select "([^"]|\"*)" from "([^"]|\"*)"
which in your case is
I select "Take Out" from "category"
Here is the LIST of already available Gherkin methods

Selenium IDE: this.browserbot.getUserWindow().typeList.filter returns error on IE8

I have faced with following trouble during working with Selenium.
I need to verify that some value exists in list and I use the following code:
assertEval
this.browserbot.getUserWindow().typeList.filter(function(v) { return v[0] === 'Type_${r_suffix}'; })[0][0];
Type_${r_suffix}
This works file on Firefox, but on IE 8 returns error: Object doesn't support this property or method.
Could someone have an idea where is a problem?
As the MDN docs say, the filter() method is available only for IE9 and above.
Your're just using a too new technology. Filter it manually using a for loop or insert the code for Array.prototype.filter (from the MDN) to have access to it.

Manual input from user while running selenium IDE script

can user is able to give manual input while running selenium IDE script?
For ex. If there is name field then can we open input box everytime script runs so that user can give his input for name field?
Let me know whether it is possible or not..
If yes then please suggest me a solution.
Thanks in advance
You can use the following script to invoke a javascript prompt in order to get the value
<tr>
<td>storeEval</td>
<td>prompt("Please enter your FirstName")</td>
<td>firstName</td>
</tr>
Then accessing the value is a case of using ${firstName}.
EDIT: Since Selenium IDE 2.5.0, the script needs to look like this:
<tr>
<td>storeEval</td>
<td>javascript{prompt("Please enter your FirstName")}</td>
<td>firstName</td>
</tr>
As of 2020 using Selenium IDE 3.16.1, I found the following config worked by the suggested answers above. (I re-answered the question as above answers did not clearly combined all pieces)
Command : execute script
Target : return prompt("Question Text","Default value");
Value : yourVariableName
and fill in the input box by the stored var:
Command : type
Target : (your selector)
Value : ${yourVariableName}
In Selenium IDE 2.8.0:
Capture the test session entering the login and password. Edit the Command for each and change from "type" to "waitForText" and remove the values in the Value fields previously stored for login and password. Re-run the saved test script from the IDE.
Since you specifically asked about Selenium IDE, the answer is no. But you can pause the script and let the user type their name, then have the script continue. I've heard of folks using this technique for handling CAPTCHAs, which of course are not easily automatable.
You could use the technique suggested here which uses the Selenium WebDriver and Java's BufferedReader. I don't think it can be adapted for Selenium IDE, but the technique should work fine with Selenium RC.
The basic idea is:
Issue Selenium commands up to the point where you want to capture user input.
Call the following code to capture the user input to a BufferedReader.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
reader.readLine();
Continue your Selenium commands
(Note, if you are using C#, there is a discussion here on how to use Console.In.ReadLine(); instead of BufferedReader).
Just a minor modification to Stephen Binns response. I'm running Selenium IDE 2.5.0 and my test looks like this:
<tr>
<td>store</td>
<td>javascript{prompt("password")}</td>
<td>password</td>
</tr>
Without the javascript{} it wouldn't prompt.
The proposed solution works fine for selenium IDE (tested for 2.5)
<tr>
<td>store</td>
<td>javascript{prompt("password")}</td>
<td>password</td>
</tr>
Use Thread.Sleep(20000);
This will freeze everything for 20s and you can enter whatever fields you want to enter manually in that time period
none of the accepted answers worked for me. Here is how I solved it:
Create new command (at the top to store my variable that I wanted to use in 30 places.)
Command: execute script
Target: return "Test Iteration #13"
Value: VarName
then in the 30 places I wanted to use that variable. I put this
Value: Enter some text into the web input box and my test iteration number is ${VarName}