I am trying to instantiate a driver session using the IE capabilities to ignore the protected mode settings in Internet Explorer, but I am unsure of the syntax.
I have tried:
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.ie().introduceFlakinessByIgnoringProtectedModeSettings(true).build();
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.ie().introduceFlakinessByIgnoringProtectedModeSettings, true.build();
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.ie().ignoreProtectedModeSettings(true).build();
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.ie().introduceFlakinessByIgnoringProtectedModeSettings(true).build();
var driver = new webdriver.Builder().withCapabilities({ "browserName": "ie" }, {"ignoreProtectedModeSettings": "true"}).build();
var driver = new webdriver.Builder().withCapabilities({ "browserName": "ie" }, {"introduceFlakinessByIgnoringProtectedModeSettings": "true"}).build();
Thus far none have worked. What is the correct sytax for this in Javascript? Thanks!!!
After having the same problem and going through the code for selenium-webdriver, I found the following to work:
const Capabilities = require('selenium-webdriver/lib/capabilities').Capabilities;
let capabilities = Capabilities.ie();
capabilities.set('ignoreProtectedModeSettings', true);
const driver = new webdriver.Builder().withCapabilities(capabilities).build();
Related
I want to know how to control the browser that has been opened? I’ve read the API docs, but I can't find the way to do it.
like java
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
WebDriver driver = new ChromeDriver(options);
or python
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)
But how to do this by nodejs (javascript) ???
I’m so confused
Taken from https://medium.com/dailyjs/how-to-setup-selenium-on-node-environment-ee33023da72d
The script below will open a chrome browser, input a term, submit the
form, and return the page title. If the test is successful, then it
should print out Test passed
const webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
const driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
driver.get('http://www.google.com').then(function(){
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver\n').then(function(){
driver.getTitle().then(function(title) {
console.log(title)
if(title === 'webdriver - Google Search') {
console.log('Test passed');
} else {
console.log('Test failed');
}
driver.quit();
});
});
});
The below step will help you :
require('chromedriver');
var webdriver = require('selenium-webdriver');
var chrome = require("selenium-webdriver/chrome");
var chrome = require("selenium-webdriver/chrome");
var options = new chrome.Options();
options.options_["debuggerAddress"] = "127.0.0.1:9222";
var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
driver.get("https://www.google.com")
I'm trying to scrape javascript generated html objects from a website. I've tried many different libraries and I found out that selenium has everything i need.
I've tried to run the driver without being in headless mode, and it WORKS,
but that's not what I need. I need a background task to keep the user interface as clean as possible.
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--no-startup-window");
chromeOptions.AddArgument("--user-agent=" + Settings.globalUserAgent);
chromeOptions.AddArgument("--log-level=3");
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
service.SuppressInitialDiagnosticInformation = true;
using(var driver = new ChromeDriver(service, chromeOptions))
{
driver.Url = "https://example.com";
driver.Navigate().GoToUrl("https://example.com/otherpage");
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("sub-conv-fu")));
string source = driver.PageSource;
if (source.Contains("some string:"))
{
File.WriteAllText("test.txt", source);
} else
{
File.WriteAllText("test.txt", source);
return "Error";
}
}
return "";
This line of code contains a variable which I want to get. It's loaded using javascript
var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("sub-conv-fu")));
It is working if I remove the "--headless" tag.
Here is the JavaScript code:
function SendMail(to,body,sub)
{
var theApp
var theMailItem
var theApp = new ActiveXObject("Outlook.Application")
var theMailItem = theApp.CreateItem(0)
theMailItem.to = to
theMailItem.Subject = (subject);
theMailItem.Body = (msg);
//theMailItem.display()
theMailItem.send()
}
However, I would like to why we can create an ActiveX for the Outlook and what's the relationship between them.
If we can create an ActiveX to automate the Outlook, can we embed the Outlook in the web page?
Any explanation is appreciate.
I am trying to run assertion for testing with selenium webdriver through node js but it says undefined, I get the page title which is URL of the page then assert it, looks like I have to import sth for assertion, please help, also please tell me if selenium works fine with node js here is my code:
var webdriver = require('selenium-webdriver'),
//var test = require('selenium-webdriver/testing'),
nodeThen = require('node-then');
var assert = require('assert');
//var jsdom = require("jsdom");
//var document = require('jquery');
var xpath = require('xpath');
//var driver = new webdriver.Builder().
// withCapabilities(webdriver.Capabilities.chrome()).
//build();
function createDriver() {
var driver = new webdriver.Builder()
.usingServer('link')
.withCapabilities(webdriver.Capabilities.chrome())
.build();
driver.manage().timeouts().setScriptTimeout(10000);
return driver;
}
var driver = createDriver();
var By = webdriver.By;
driver.get("URL")
.then(function(){
driver.sleep(10000);
var element=driver.findElement(By.id("get-started"));
element.click();
})
.then(function(){`enter code here`
return driver.getTitle();
})
.then(function(title) {
//console.log(title);
//driver.manage().timeouts().setScriptTimeout(50000);
if (title == ('URL')) {
console.log("pass");
}
//
I was searching for the same issue and I found this snippet which is working for me
driver.findElement(By.id('elementId'))
.getText().then(textValue => {
assert.equal('tested string', textValue);
});
I found it in the examples files of selenium-webdriver's github repo
Did you install asserts? The command would be npm install asserts. Also, you need var Asserts = require('asserts');
This is the example you are looking for
// Require chai.js expect module for assertions
const chai = require('chai');
const expect = require('chai').expect;
// Application Server
const serverUri = '0.0.0.0:3000';
// Official selenium webdriver testing setup
const webdriver = require('selenium-webdriver');
describe('basic test', function () {
let driver;
before(() => {
// Start of test use this
driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
console.log("Selenium Webdriver Chrome Started");
});
after(function(){
// End of test use this.
driver.quit();
});
it('should be on correct page', function (done) {
this.timeout(10000);
driver.get(serverUri);
driver.getTitle().then(function(title) {
expect(title).to.equal('Some String Here');
done();
console.log("Selenium Webdriver Chrome Shutdown");
})
});
});
This seems like it should be easy. I've never used JScript before and I'm looking at the JScript api provided by microsoft but no luck. Here's what I have:
var fso, tf;
fso = new ActiveXObject("Scripting.FileSystemObject");
tf = fso.CreateTextFile("New Tracks.txt", true);
var objShell = new ActiveXObject("Shell.Application");
var lib;
lib = objShell.BrowseForFolder(0,"Select Library Folder",0);
items = lib.Items()
for (i=0;i<items.Count;i++)
{
fitem = items[i];
tf.WriteLine(fitem.Name);
}
WScript.Echo("Done");
tf.Close();
I get an error about fitem.Name that it's not an object or null or something. However, there are definitely files in that folder.
The items variable in your script holds a FolderItems collection rather than an array. To access the collection's items, you need to use the Items(index) notation. So, replacing
fitem = items[i];
with
fitem = items.Item(i);
will make the script work.
This works for me, I had to change the path to the file or I get access denied (win 7).
<script language="JScript">
var fso, tf;
fso = new ActiveXObject("Scripting.FileSystemObject");
tf = fso.CreateTextFile("c:\\New Tracks.txt", true);
var objShell = new ActiveXObject("Shell.Application");
var lib;
lib = objShell.BrowseForFolder(0,"Select Library Folder",0);
var en = new Enumerator(lib.Items());
for (;!en.atEnd(); en.moveNext()) {
tf.WriteLine(en.item());
}
WScript.Echo("Done");
tf.Close();
</script>
Apparently you can't access it like an array and have to call the Item() method.