Currently, I need to use proxy with authentication, on selenium-webdriver on Firefox.
I successfully connect to Tor using :
var option = new Options();
option.headless()
option.setPreference('network.proxy.type', 1)
.setPreference('network.proxy.socks', '127.0.0.1')
.setPreference('network.proxy.socks_port', 9050)
.setPreference('network.proxy.socks_remote_dns', true)
.setPreference('network.proxy.socks_version', 5)
let driver = await new Builder()
.forBrowser(Browser.FIREFOX)
.setFirefoxOptions(option)
.build();
But I don't find how to pass username and password for other proxy.
I looked on Selenium's github, but nothing worked. This is the exemple on the file's comment but not working:
let capabilities = new Capabilities();
capabilities.setProxy(proxy.socks('username:pass#host:port'))
// for tor
capabilities.setProxy(proxy.socks('host:port'))
let driver = await new Builder()
.withCapabilities(capabilities)
.forBrowser(Browser.FIREFOX)
.setFirefoxOptions(option)
.build();
Please help me :(
You could try using the following with setPreference itself:
.set_preference("network.proxy.socks_username", USERNAME)
.set_preference("network.proxy.socks_password", PASSWORD)
Related
Metamask Confirm button not working, couldn't confirm transaction for a smart contract.
I use JS and WalletConnectProvider (website project). Connecting to Metamask by WalletConnect, then call transfer function for custom token contract. I use the same code on desktop and it works and transferring token. Exactly the same code doesn't work on mobile (for Metamask Mobile app). Checked IOS and also Android - the same issue.
Please tell me what is wrong with my code:
<script src="https://cdn.jsdelivr.net/npm/#walletconnect/web3-provider#1.8.0/dist/umd/index.min.js"></script>
<script src="https://[mywebsitescriptspath]/web3.min.js"></script> // 1.8.0
<script type="text/javascript">
var contract
var accountFrom
const ABI = "... abi here....."
var provider = new WalletConnectProvider.default({
infuraId: 'my infura id',
rpc: {
1: "https://mainnet.infura.io/v3/[myinfuraid]",
56: "https://bsc-dataseed.binance.org/"
},
})
const contractAddress = '0xcontraddresshere'
const receiver = '0xreceiveraddresshere'
var connect = async () => {
await provider.enable()
var web3 = new Web3(provider)
web3.givenProvider = web3.currentProvider
web3.eth.givenProvider = web3.currentProvider
web3.eth.accounts.givenProvider = web3.currentProvider
window.w3 = web3
contract = new w3.eth.Contract(ABI, contractAddress)
await w3.eth.getAccounts().then(accounts => {
accountFrom = accounts[0]
})
}
connect()
// function called after the button click
var sendtransaction = async () => {
let vall = 100
let calcAmount = w3.utils.toWei(vall.toString())
let transfer = await contract.methods.transfer(receiver, calcAmount);
await transfer.send({from: accountFrom})
.on('transactionHash', function(hash){
console.log(hash)
})
}
</script>
I tried many different things but it doesn't work.
Tested on wifi, on 4g, on different mobile browsers, on different smartphones (android and IOS).
no success.
The problem started from 5.9.0 Metamask app version.
UPDATE:
Now at 5.10.0 version it doesn't recognize custom contract token. For example when I want to transfer 1 token, it shows 1 BNB.
Last version was better :))
There are open issues on github:
https://github.com/MetaMask/metamask-mobile/issues/5193
https://github.com/MetaMask/metamask-mobile/issues/5235
https://github.com/MetaMask/metamask-mobile/issues/5260
No solution till now - after 14 days.
Change version metamask, working me version - 5.7.0
This issue was solved with the Metamask 5.11.0 updated for IOS 16.1.1. Update your Metamask app to 5.11.0.
Reference: https://github.com/MetaMask/metamask-mobile/issues/5260
Yes, actually they didn't resolve the issue.
In my case, different ERC20 tokens have different result.
On this token, the blue confirm button doesn't work.
https://etherscan.io/token/0x377e0c5d3738FAcd2D4c1CA192c774e978E8e95b#writeContract
But on USDC (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)
It works well.
iOS ver 16.1.2
MetaMask v5.12.0
I am setting up the first automated tests for a web app I'm working on, and have hit a state I don't understand.
It is a browser app, so I start a very simple static server:
import http from 'http';
let serve = serveStatic(path);
server = http.createServer(function(req, res) {
var done = finalhandler(req, res);
serve(req, res, done);
});
During my testing, I receive an error message HTTP method not allowed
let options = new firefox.Options();
options.headless();
let capabilities = webdriver.Capabilities.firefox().set('acceptInsecureCerts', true);
let driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.withCapabilities(capabilities)
.build();
await driver.get('http://127.0.0.1:3030/index.html');
let tab = await driver.findElement(state.By.css('ps-tabpanel'));
tab = await tab.getShadowRoot(); // HTTP method not allowed
On a hunch, I changed this to an HTTPS connection
import http from 'https';
In this case I receive a very different error
await driver.get('https://127.0.0.1:3030/index.html');
// Reached error page: about:neterror?e=nssFailure2&u=https%3A//127.0.0.1%3A3030/index.html&c=UTF-8&d=%20
So my main question is, what am I doing wrong to access the shadowRoot using Javascript Selenium?
For reference
mocha + selenium + firefox
gitpod environment
have an earlier test that simply verifies I can connect to example.com just to prove the connection is working.
In an attempt to work around the error, I switched to the javascript executor. This raised a different error message (cyclical object).
This led me to a different stackoverflow question
https://stackoverflow.com/a/67223939/1961413
According to that answer, this is a known defect in the GeckoDriver/Firefox.
Based on that I switched to the ChromeDriver/Chrome, and was able to find the ShadowRoot.
https://www.npmjs.com/package/chromedriver
let driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
await driver.get('http://127.0.0.1:3030/index.html');
let tab = await driver.findElement(state.By.css('ps-tabpanel'));
tab = await tab.getShadowRoot();
I create Front End Web Page For Ether Smart Contract. I before Used Web3 Library And Meta Mask. Now My Web Page is Work. But When I Upload Site On Host For Using Others, When I Test My Web Page In Other Systems And Other Browsers That Don't Used/Installed Meta Mask Extensions, I'm Getting An Error.
Please Some One Help Me How Do I Connect A Web Page To A Contract?
I Before Used This Code For Connecting :
<script >
if (typeof window.ethereum !== 'undefined')
{
console.log('MetaMask is installed!');
}else{
console.log('MetaMask not installed!');
alert("Please install Metamsk wallet first, then try again");
}
const accounts = ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
const showAccount = document.querySelector('.showAccount');
var contract;
const accounts = ethereum.request({ method: 'eth_requestAccounts' });
const account = accountsH[0];
const showAccount = document.querySelector('.showAccount');
web3 = new Web3(web3.currentProvider);
var address = "0x6246.../* My Contract Address */...5E7a";
var abi =[/* My ABI */];
contract = new web3.eth.Contract(abi, address);
</script>
And It Work. But In Other Browsers That Meta Mask Is Inactive Or Not Installed, I See Error.
I Use Html And Java Scripts For Front End Programming.
I found the answers to my questions.
I have to use infura
check this page
and at first create project at site. and get ID
use this code
web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/3c6/*Your Own ID*/01753"));
I'm using selenium with Tor but it's not working , i saw that there is a library for doing that but only with python . Can this be done with javascript ? I tried that but it doesn't work.
const {Builder, By, Key, until} = require('selenium-webdriver');
var driver = new Builder()
.forBrowser('tor')
.build();
driver.get('https://www.google.com')
As far as I remember, this can be done only from Java and Python.
I had trouble getting the latest geckodriver (0.21.0) and Selenium (3.13.0) to fetch a web page after launching the Tor Browser Bundle. I think it may be incompatibilities with the older Firefox version Tor uses and the geckodriver but am not sure.
If you're just trying to use selenium-webdriver to use the Tor network, try this:
const webdriver = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
var options = new firefox.Options();
options.setPreference('network.proxy.type', 1) // manual proxy config
.setPreference('network.proxy.socks', '127.0.0.1')
.setPreference('network.proxy.socks_port', 9050)
.setPreference('network.proxy.socks_remote_dns', true) // resolve DNS over Tor
.setPreference('network.proxy.socks_version', 5)
let driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
driver.get('https://example.com/')
You will need to run Tor using the expert bundle or install and run it natively.
Here's what I tried for actually getting Tor Browser to automate. It launches everything correctly but never navigates to the page.
const webdriver = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
var options = new firefox.Options();
options.setBinary('/home/me/Desktop/tor-browser_en-US/Browser/start-tor-browser');
options.addArguments('--detach');
(async function run() {
let driver = await new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
await driver.get('https://example.com/')
})();
Just to re-iterate, this second example isn't working. On Mint 18 and Tor Browser 7.5.6 (FF ESR 52.9.0) it launches Tor and the browser just fine, but will not navigate to a page.
I need to be able to run phantomjs with the following arg:
--ignore-ssl-errors=true
The page I'm testing uses a self-signed cert so I need the arg to open the page. I'm trying to pass the arg in webdriver using the snippet below:
capabilities = webdriver.Capabilities.phantomjs();
capabilities.set('service_args', '--ignore-ssl-errors=true');
driver = new webdriver.Builder().
withCapabilities(capabilities).
build();
Is the correct way to pass the service_args? I actually hope not since I can't load my test page. I can open the page by running:
phantomjs --ignore-ssl-errors=true myTest.js
Here is the code in myTest.js
var page = new WebPage();
page.open('https://my.somefaketestpage.com/', function (status) {
just_wait();
});
function just_wait() {
setTimeout(function() {
page.render('screenshot.png');
phantom.exit();
}, 2000);
}
The correct answer is:
caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
driver = new PhantomJSDriver(caps);
documented here: https://github.com/detro/ghostdriver/issues/233
In case someone will need it for facebook/php-webdriver CLI arguments can be passed to PhantomJS in a following manner:
$driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', [
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::PHANTOMJS,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
'phantomjs.cli.args' => ['--ignore-ssl-errors=true']
]);
Reading this I got really confused, as the accepted answer is in Java, and the GhostDriver constants and stuff aren't present. For those who are also confused, this worked for me:
var webdriver = require('selenium-webdriver'),
Capabilities = webdriver.Capabilities;
var capability = Capabilities
.phantomjs()
.set('phantomjs.cli.args', '--ignore-ssl-errors=true');
var driver = new webdriver
.Builder()
.withCapabilities(capability)
.build();