Unable to locate iframe in Selenium Webdriver - java

I am using Selenium 2 WebDriver API and receiving Unable to locate element Error when I am running my Tests. The element is an iframe. But wait , when I run the test locally (in my local server) it works fine (via driver.switchTo().frame("frame id");) approach, but when my tests run on live server, the error arrives.
The one difference between them is that the live server is running on https.
Is that the issue that WebDriver is not recognizing iframe over SSL ??
Any Help is appreciated.

Use driver.switchTo().frame(index);

Related

How to turn off 'Enhanced Tracking Protection' for Firefox browser via Selenium WebDriver?

My Selenium Java test script runs on Firefox browser.
Recently, it has started failing on applications where 'Enhanced Tracking Protection' is turned on.
https://support.mozilla.org/en-US/kb/enhanced-tracking-protection-firefox-desktop
How can I disable/turn it off via Selenium Web Driver? Is there any preference or capability through which I can turn it off in the Firefox profile?
I'm using Selenium with PowerShell and I had the same issue.
This solution works for me
[OpenQA.Selenium.Firefox.FirefoxProfileManager]$ProfileManager= [OpenQA.Selenium.Firefox.FirefoxProfileManager]::new()
[OpenQA.Selenium.Firefox.FirefoxProfile]$FirefoxProfile = $ProfileManager.GetProfile($ProfileName)
$FirefoxProfile.SetPreference("pref.privacy.disable_button.tracking_protection_exceptions", $true)

Unable to sendkeys/click with selenium Java or JavascriptExecutor

These are the steps that my code is running.
I start the chromedriver with the secure shell appt - no issues, it launches the browser and appt correctly
chromeOptions.addExtensions(new File("src/test/resources/win32/browserprofile/Secure-Shell-App_v0.8.43.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
I then navigate using driver get to the chrome URL setup page to send connection data.
driver.get("chrome-extension://pnhechapfaindjhompbnflcldabbghjo/html/nassh.html");
While on this page from the image below, I tried to send keys or click on any of the fields with sendkeys or click and I get the following error.
I have tried multiple ways and im getting the same results: org.openqa.selenium.WebDriverException: unknown error: Cannot set property 'value' of null
Here is my code
//Webdriver
driver.findElement(By.xpath("//*[#id='field-description']")).sendKeys("aabb");
driver.findElement(By.id("field-username")).click();
driver.findElement(By.id("field-username")).sendKeys("useridval");
driver.findElement(By.id("field-hostname")).click();
driver.findElement(By.id("field-hostname")).sendKeys("10.0.0.0");
//JavascriptExecutor
// This will execute JavaScript in your script
((JavascriptExecutor)driver).executeScript("document.getElementById('field-username').value='migsrcrfuser';");
Question: Is this even possible, I see an id and the id is unique; furthermore, I also tried xpath and received the same result. Thoughts
Breift description: Terminal emulator and SSH client.
Secure Shell is an xterm-compatible terminal emulator and stand-alone ssh client for Chrome. It uses Native-Client to connect directly to ssh servers without the need for external proxies.
https://chrome.google.com/webstore/detail/secure-shell-extension/iodihamcpbpeioajjeobimgagajmlibd
Update your ChromeDriver to 2.37 (the latest) from https://sites.google.com/a/chromium.org/chromedriver/downloads
I think that you are using Chrome v65
The issue was frame related. I used this code to identified how many frames and then send keys to the correct frame. phew!
int size = driver.findElements(By.tagName("iframe")).size();
System.out.println(size);
driver.switchTo().frame(1); // Switching the inner Frame with 1 0 for outer fram
driver.findElement(By.xpath("//*[#id='field-description']")).sendKeys("9109");

Selenium can't start session because url doesn't support http post

I'm trying to run some Selenium tests for an application while it is started, but am getting a runtime exception:
Could not start Selenium session: HTTP method POST is not supported by this URL
The application we made has no need for a POST method. Is there any way to make Selenium work without needlessly implementing one? Why is it required in the first place?
The parameters to pass for DefaultSelenium are as follows according to the api documentation:
serverHost - the host name on which the Selenium Server resides
serverPort - the port on which the Selenium Server is listening
browserString - the command string used to launch the browser
browserURL - the starting URL including just a domain name
You need to direct it to where an instance of your selenium server is running (which could be remotely or locally). I am going to guess that localhost:8080 is where you have deployed a separate application that you want to test with selenium.
So, the details you provide are for the selenium server, not for your application. If you download the standalone server and run it locally, you only need to change the port to match that of the selenium server instance. You can download the selenium standalone server from their main website, and when you run it, it will tell you the port that it uses (by default it is 4444).
Why not just use WebDriver instead?
WebDriver driver = new FirefoxDriver();
driver.get("URL")
You can read more about how to use it on the documentation page on the selenium website.

Unable to clear Browser cookies and Session Data with Selenium

I have been using Java Selenium WebDriver along with Appium to perform tests on Mobile environment be it Emulator(Genymotion) or Physical devices (Android). I am using chromedriver, which I am using to perform tests on Web App in Chrome browser. I am looping my cases for multiple sets of data but the application requires a full browser Cookie and all Session data to be deleted before each loop starts.
I tried using driver.Manage().Deleteallcookies(), but it did not work out for me. I read in some threads to try creating a new session of the browser before each loop. So I tried driver.quit() but it ends the chromedriver session and ends the test. I also tried driver.close() but got the same results as driver.quit().
Can any one suggest a way to delete the browser cookies and session data in chrome browser??
My Appium version:1.3.4.1
Chromedriver version:2.3
Device/Emulator i am trying to test on : Nexus5/Samsung Note 3 Android:4.4.4/5.0
You can try using the following to ensure a clear session. Note I never tested that myself. My understanding is that selenium by default create a new session unless you specified something different or load a profile.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
ChromeDriver driver = new ChromeDriver(capabilities);

Delete start message from selenium webdriver ie

I m using Selenium IE Webdriver.I want to delete "This is the initial page of webdriver server." from IEDriverServer.exe file of Selenium IE Webdriver. I opened the IEDriverServer.exe file in notepad++ and deleted that line from it and again add it in my classpath.But then i get this error:
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
How can we do that.Please someone tell me.
You can't just edit an executable file like that. You have undoubtedly ruined the executable and now should redownload it from the Selenium site.
Regardless, this is expected behaviour. The IEDriver must have somewhere to go to begin with.
There is a setting that configures this URL called InitialBrowserURL. If this is not configured in your code, then the default is used.
Configure this to what you want. Most cases it can be configured to just go to the home page of your application.

Categories

Resources