All:
I am running a simple Java application with Selenium WebDriver.
I was able to successfully run a search
on http://www.google.com using org.openqa.selenium.htmlunit.HtmlUnitDriver
I tried to run the same search term on http://www.yahoo.com as shown in the following code excerpt:
CharSequence[] searchTerm = { "bbc", "news" };
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new HtmlUnitDriver();
// And now use this to visit Google
driver.get("http://www.yahoo.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
//searchTerm = "bbc news";
// Enter something to search for
element.sendKeys(searchTerm);
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
Howefver, it gives me the following error:
Oct 17, 2014 3:18:44 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected [DNR="deleted", version:0, domain:.www.yahoo.com, path:/, expiry:Thu Oct 17 15:18:45 IST 2013] Illegal domain attribute "www.yahoo.com". Domain of origin: "in.yahoo.com"
Exception in thread "main" 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.43.1', revision: '5163bce', time: '2014-09-10 16:27:58'
System info: host: , ip: , os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:1001)
Why does it work fine for http://www.google.com but fails for http://www.yahoo.com ?
Why does it throw the "Exception in thread main org.openqa.selenium.NoSuchElementException Unable to locate element with name q" error?
Update with Answer
Thanks to #Sriram and #ivan_ochc , I am able to run the following code that searches http://www.yahoo.com properly
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new HtmlUnitDriver();
// And now use this to visit Google
driver.get("http://www.yahoo.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("p"));
http://www.yahoo.com doesn't have element with name="q", it has element with name="p"
Related
I am practicing selenium with practiceautomation.com site. I have problem with registration - my selector cannot locate option with index.
code:
Select yearSelector = new Select(driver.findElement(By.id("years")));
yearSelector.selectByIndex(2000);
And I got something like:
org.openqa.selenium.NoSuchElementException: Cannot locate option with index: 2000
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'DESKTOP-NN5LV43', ip: '192.168.0.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.1'
Driver info: driver.version: unknown
It is strange, because I use also
Select dateSelector = new Select(driver.findElement(By.id("days")));
dateSelector.selectByIndex(15);
And everything works fine and the day on the list is normally selected
Picture:
Year
As you can see, years are visible.
You try to select by index 2000 and errors says no option with index 2000. Maybe you want to select by value?
Select yearSelector = new Select(driver.findElement(By.id("years")));
yearSelector.selectByValue("2000");
public void selectByIndex(int index)
The above method select the option at the given index. This is done by examining the "index" attribute of an element, and not merely by counting.If no matching option elements are found then NoSuchElementException is thrown
Check for index attribute in html with value as 2000 it should not be there so try with
selector.selectByIndex(1); // see first visible year is selected or not
OS:Windows 10
Execution Environment : JavaSE-1.8 (jre1.8.0_144)
JARs and class folders on build path:
client-combined-3.6.0-sources.jar
client-combined3.6.0.jar
selenium-server-standalone-3.6.0.jar
Browser:
FireFox 56.0
Code Snippet:
System.setProperty("webdriver.firefox.marionette","C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe");
WebDriver driver = new FirefoxDriver ();
driver.get("https://www.facebook.com");
Error:
Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:112)
at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:97)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:217)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:140)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at FacebookFriends.main(FacebookFriends.java:18)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:45149/hub/status] to be available after 45005 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:110)
... 8 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 9 more
First of all You are using a little bit old version of gecko driver. The newest from: https://github.com/mozilla/geckodriver/releases
Then You need to set up system property with:
File gecko = new File("C:/Users/admin/Downloads/geckodriver-v0.19.0-win32/geckodriver.exe");
System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());
If You really want to use marionette check answers on: Difference between webdriver.firefox.marionette & webdriver.gecko.driver
I haved this error for 2 days, the solution for me was in Set.Plataform put Platafor.ANY or Plataform.Windows because Plataform.WIN10 not worked, marionette wasn't necessary and I added and neether works, only works this. I hope this helps someone else:
public class Main {
public static RemoteWebDriver driver;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "D:/Lib/geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities().firefox();
desiredCapabilities.setPlatform(Platform.ANY);
desiredCapabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://172.20.19.182:5557/wd/hub"), desiredCapabilities);
driver.navigate().to("http://www.google.com");
driver.findElementByName("q").sendKeys("execute automation");
driver.findElementByName("q").sendKeys(Keys.ENTER);
driver.close();
// write your code here
}
}
You can also try using double \\ in the path of the geckodriver.
Also instead of using :
System.setProperty(
"webdriver.firefox.marionette",
"C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe");
Can you try using
System.setProperty(
"webdriver.gecko.driver",
"C:\\Users\\admin\\Downloads\\geckodriver-v0.11.1-win32\\geckodriver.exe");
Title : Problem Resolved
Solution Accepted :
- Use latest version of gecko driver
Code Used
- System.setProperty("webdriver.gecko.driver","C:\Marionette\geckodriver_1.exe" );
I am trying to scroll and its not working for both Android and iOS, Can you please help me on this.
Look forward to hear back from you.
Did try with ScrollTO and ScrollToExact as both of them are deprecated now, so did try with this:
String str = "CADILLAC";
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+str+"\").instance(0))").click();
Still does not work.
Did go through many blogs , videos , course content and material no one has explained or there a specific solution on how to handle this
Did try with below,still gets the error
org.openqa.selenium.WebDriverException:
driver.findElementByAndroidUIAutomator("UiSelector().resourceId(\"current_value_tv\").text(\"All Makes\")").click();
driver.findElementByAndroidUIAutomator("UiSelector().className(\"android.widget.TextView\").text(\"AUSTIN HEALEY\")").click();
org.openqa.selenium.WebDriverException: An unknown server-side error
occurred while processing the command. (WARNING: The server did not
provide any stacktrace information)
Command duration or timeout: 45 milliseconds
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'NCA1026471', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version:
'1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=C:\Appium\workspace\Lokesh\app\app-release.apk,
appPackage=au.com.carsguide, rotatable=true,
networkConnectionEnabled=true, noReset=true, warnings={},
handlesAlerts=true, deviceName=Carsguide Product, version=0.17.0,
platform=ANDROID, appActivity=au.com.carsguide.activity.HomeActivity,
desired= {app=C:\Appium\workspace\Lokesh\app\app-release.apk,
appPackage=au.com.carsguide,
appActivity=au.com.carsguide.activity.HomeActivity, noReset=true,
platformVersion=5.0, browserName=, platformName=Android,
deviceName=Carsguide Product, device=Android}, acceptSslCerts=true,
platformVersion=21, automationName=selendroid, browserName=selendroid,
takesScreenshot=true, javascriptEnabled=true, platformName=android,
device=Android}]
Session ID: e90cac4d-38aa-99fd-2dd2-70cc09a0e717
*** Element info: {Using=-android uiautomator, value=UiSelector().resourceId("current_value_tv").text("All Makes")}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
you can try this below code, i was trying this code on settings page..
AppiumDriver driver = new AndroidDriver(new URL(""), cap1);
driver.scrollTo("About phone");
Pass the String which is present in the bottom of your app page.
driver.scrollTo("Enter your value");
Use appropriate wait Statements.
use driver.swipe instead of driver.scroll
http://automationbyharsh.blogspot.in/
visit this blog to get full documentation of swipe method for Android and IOS.
scrollTO method is not consistent in appium for android apps. so try the following.
go till model listing page
try the below code snippet , This was for flipkart app
it may help you with your app
driver.findElementById("com.flipkart.android:id/search_autoCompleteTextView").sendKeys("Reebok Shoes" +"\n");
Thread.sleep(8000);
Dimension size = driver.manage().window().getSize();
System.out.println(size);
int Starty=(int)(size.height*0.90);
int Endy=(int)(size.height*0.10);
int Startx=(int)(size.width*0.50);
WebElement ele_item = driver.findElementByClassName("android.widget.TextView");
Thread.sleep(3000);
do
{
List<WebElement> ele_item2 = driver.findElementsByXPath("//*[#index='2'][#text='Reebok SPEED XT Running Shoes'][#class='android.widget.TextView']");
int size2 = ele_item2.size();
System.out.println(size2);
if(size2>0)
{
driver.findElementByXPath("//*[#index='2'][#text='Reebok SPEED XT Running Shoes'][#class='android.widget.TextView']").click();
break;
}
driver.swipe(Startx, Starty, Startx, Endy, 1000);
Thread.sleep(2000);
} while(ele_item.isDisplayed()==true);
I'm trying to do a scraping exercise with Selenium, but I'm having a few problems.
Here is my code:
package ScraperPakage;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import java.util.List;
public class ScraperClass {
public static void main(String[] args) {
//Create a new instance of Firefox Browser
System.setProperty("webdriver.gecko.driver", "C:\\Users\\xxxx\\Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//Open the URL in firefox browser
driver.get("http://www.budgettravel.ie");
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
List<WebElement> titles = driver.findElements(By.cssSelector("div.travelOfferList"));
for (int j = 0; j < titles.size(); j++) {
System.out.println( "\t - " + titles.get(j).getText() ) ;
}
driver.quit();
}
}
The code returns the list of offer holidays, but ends with a list of errors that I don't know how to resolve.
Here is the output:
JavaScript warning: resource://cck2/CCK2.jsm, line 998: unreachable code after return statement
JavaScript warning: resource://cck2/Preferences.jsm, line 556: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
1472551987508 Marionette INFO Listening on port 62410
JavaScript warning: https://normandy.cdn.mozilla.net/static/bundles/selfrepair-068962304d04a2173e88.94ed0f93a4f3.js, line 11002: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
Page title is: Cheap Holidays 2016/ 2017, Cheap Sun Holidays from Dublin, All Inclusive Sun Package Holidays from Ireland, Cheap Last Minute Holidays & Deals, All Inclusive Late Holiday Deals - Budget Travel
- Last Minute Deals
Where
When
Nights
From
Costa Blanca
21 Sep
7
€185pp
[ ... REST OF THE LIST ...]
Costa Dorada
22 Oct
7
€146pp
[Child 14212] WARNING: pipe error: 232: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 487
[Child 14212] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2027
[NPAPI 13576] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2027
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'xxxx', ip: 'xxxx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, appBuildId=20160623154057, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0.1, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop}]
Session ID: 3ad95378-01d1-4c6c-a3ce-24f992fb5289
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:670)
[... OTHER LINES LIKE THE LINE JUST ABOVE ...]
Also, the are two windows opening with 'Plugin Container for Firefox has stopped working'
Problem signature:
Problem Event Name: APPCRASH
Application Name: plugin-container.exe
Application Version: 47.0.1.6018
Application Timestamp: 576c9637
Fault Module Name: mozglue.dll
Fault Module Version: 47.0.1.6018
Fault Module Timestamp: 576c85ba
Exception Code: 80000003
Exception Offset: 0000f02b
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 6153
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Any ideas why I'm getting the errors at the end and the windows opening at the end.
Thanks
Code:
public void Test2() throws Exception{
Thread.sleep(5000);
driver.findElement(By.id("cboMenu")).click();
driver.findElement(By.xpath(".//*[#id='cboMenu/option[3]")).click();
}
Error:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cboMenu"}
Command duration or timeout: 31 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'venu-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 0f859bed-35df-4eba-a472-3bc2efec4814
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Please use explicit wait instead of the Thread.sleep(5000), like in the next example.
It will provide you much clearer error regarding what you experience.
public void Test2() throws Exception{
new WebDriverWait(driver, 3).until(ExpectedConditions.visibilityOfElementLocated(By.id("cboMenu")))
driver.findElement(By.id("cboMenu")).click();
driver.findElement(By.xpath(".//*[#id='cboMenu/option[3]")).click();
}
Next, verify your button doesn't appear in different iFrame. If you do, change the iFrame to the one you element inside:
driver.switchTo().frame("IFRAME_ID");
The IFRAME_ID is taken from the DOM:
<iframe id="IFRAME_ID">
You can next change visibilityOfElementLocated to presenceOfElementLocated, that will verify that an element is present on the DOM but does not necessarily mean that the element is visible. It can be good clue to know if your webDriver is in the correct scope with the button you try to click.
Additional tip - scroll the button you want to click on into view. Thats could be also the reason to failure.
//element is WebElement
(JavascriptExecutor)driver.executeScript("arguments[0].scrollIntoView(true);", element);
this is solved my issue :)
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.context("WEBVIEW_com.openstream.cueme.services.workbench");
Thread.sleep(10000);
driver.findElementById("userId").sendKeys("sysadmin");
driver.findElementById("CuemePassword").sendKeys("MMNext13#");
Try below code
public void Test2() throws Exception{
Thread.sleep(5000);
driver.findElement(By.id("cboMenu")).click();
driver.findElement(By.xpath(".//*[#id='cboMenu']/option[3]")).click();