Comments (10)
@stevepryde did it. #61
from thirtyfour.
@zhiburt
And for the above issue I found this
let mut caps = FirefoxCapabilities::new();
let prefs: serde_json::Value = serde_json::json!({
"general.useragent.override": "Custom"
});
caps.add_firefox_option("prefs", prefs)?;
from thirtyfour.
Yeah I think that is a good idea. As for how to adapt what is there, I'm not sure. Feel free to submit a PR if you have an idea of how you'd like to solve it.
from thirtyfour.
@stevepryde
Does FirefoxProfile even work?
Error: An argument passed to the WebDriver server was invalid:
Status: 400
Additional info:
profile is not a string
Error: invalid argument
Stacktrace:
Because this says it only accepts a Base64 encoded string
Fix: #60
from thirtyfour.
Simple test
use anyhow::Result;
use thirtyfour::{FirefoxCapabilities, WebDriver, WebDriverCommands};
#[tokio::main]
pub async fn main() -> Result<()> {
// User agent string
let user_agent = "Custom";
// Set user agent in capabilities
let mut caps = FirefoxCapabilities::new();
caps.add_firefox_option(
"prefs",
serde_json::json!({ "general.useragent.override": user_agent }),
)?;
// Start webdriver and get user agent string
let c = WebDriver::new("http://localhost:4445", caps).await?;
c.get("https://www.google.si").await?;
let js_user_agent: serde_json::Value = c
.execute_script(r#"return navigator.userAgent;"#)
.await?
.convert()?;
// Test
assert_eq!(user_agent, &js_user_agent);
// Exit
c.close().await?;
Ok(())
}
from thirtyfour.
Maye an impl like this:
This code goes in Capabilities
(This is for adding keys and supporting mutiple nestings)
fn add_key(
&mut self,
key: &[&str],
subkey: &str,
value: impl Serialize,
) -> WebDriverResult<()> {
let mut v = self.get_mut();
let part = &[subkey];
let mut keys = key.into_iter().chain(part.iter()).peekable();
// Move to last avaliable key
while let Some(key) = keys.peek() {
if v[key].is_null() {
break;
}
v = &mut v[key];
keys.next();
}
// Create missing nested objects
for key in keys {
v[key] = json!({});
v = &mut v[key];
}
// Set value
*v = to_value(value)?;
Ok(())
}
This code goes in FirefoxCapabilities
fn set_preference(
&mut self,
key: &str,
value: impl Serialize,
) -> WebDriverResult<()> {
self.add_key(&["moz:firefoxOptions", "prefs"], key, value)
}
from thirtyfour.
Or renaming FirefoxProfile
into FirefoxPreferences
and having it work the same as Capabilities
AKA having helper methods like set_user_agent(agent: &str)
, ... and a genric methods like set(key: &str, value impl Serialize)
, unset(key: &str)
, ...
from thirtyfour.
Or renaming
FirefoxProfile
intoFirefoxPreferences
and having it work the same asCapabilities
AKA having helper methods likeset_user_agent(agent: &str)
, ... and a genric methods likeset(key: &str, value impl Serialize)
,unset(key: &str)
, ...
I like this option. However I don't have bandwidth for this currently. Would you be interested in making this change?
from thirtyfour.
Thanks so much for this. I've also added your above "test" as examples/firefox_preferences.rs (modified a little to align with other examples).
from thirtyfour.
So I suppose the issue can be closed?
Good job @audioXD
from thirtyfour.
Related Issues (20)
- Error while clicking element. HOT 4
- `#shadow-root` doesn't work on Firefox with geckodriver HOT 1
- Connection refused when using containers HOT 4
- How to use selenium-manager in my code? HOT 2
- thread 'tokio-runtime-worker' panicked at 'internal error: entered unreachable code: received unknown error (no such frame) for NOT_FOUND status code' HOT 4
- How can I set the user-agent for Chromedriver? HOT 3
- Is there a way to use wait_until or something like it to way for a specific ID to be available ? HOT 2
- wait until element to disappear HOT 6
- Chrome Options example erroring HOT 2
- Does `query` work on child elements? HOT 3
- Cannot interact with WebElement HOT 1
- How to trigger onchange event without submitting the form? HOT 2
- How to set PageLoadStrategy::None in DesiredCapabilities::chrome()? HOT 1
- Running the Test without Existing Browser (HtmlUnitDriver) HOT 1
- Add cdp type from auto_generate_cdp crate HOT 2
- How to handle file picker? HOT 4
- How to capture the Chromium's requests and responses traffic using thirtyfour HOT 5
- Maintenance Status
- Device Farm incompatibility - with workaround
- Chromedriver - http incompatibility with hyper HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thirtyfour.