Comments (11)
Hi, the Capabilities struct is really limited right now but you can easily extend it with raw JSON so it should be possible to add any capabilities as long as you know the format.
For Chrome options, I believe you can do things like this:
let mut caps = DesiredCapabilities::chrome();
caps.add("goog:chromeOptions", serde_json::json!({"args": ["--disable-web-security"]}));
I only tried with --headless and it seemed to work. Let me know if it works for you.
from thirtyfour.
FYI - as of v0.6.0 (just deployed) you can now do:
let mut caps = DesiredCapabilities::chrome();
caps.add_arg("--disable-web-security")?;
The interface should actually be backwards compatible so people can still construct the capabilities struct manually if preferred.
from thirtyfour.
As I understand it, generally you should not use blocking calls like thread::sleep() during async functions, since this will block that thread and potentially prevent other futures from running until you next .await
.
If you're using tokio, have a look at https://docs.rs/tokio/0.2.11/tokio/time/fn.delay_for.html.
However, back in the world of website automation, it's also generally not ideal to use sleeps of any form to wait for things to happen on the website. Always prefer polling instead of sleeps where possible. This is because any code that uses sleeps is quite prone to timing issues and will either sometimes fail if the website was too fast/slow or otherwise your code might sleep unnecessarily long in places.
If the first click causes some element to appear or disappear, then you can effectively wait for that event to happen by repeatedly polling for that condition, and only fail after a certain number of tries (or after a certain amount of time). The thirtyfour
crate is intended to be lower level than this and will stick fairly close to the selenium spec, but you can write high-level abstractions that take care of repeatedly calling find_element
or checking whether an element has a particular attribute, until either the condition is met or a timeout is reached.
If you go down this path, sometimes it is better to set selenium's implicit wait timeout to 0 (via the WebDriver::implicitly_wait()
method) so that you don't end up with two different timeouts interfering with each other. You might also still want to call tokio's delay method to delay 500ms or so between polling attempts. It really depends on what you're trying to do and the website you're interacting with.
However, the simplest way, at least when starting out, is to just search for the element you expect to appear, relying on selenium's implicit wait to sleep for you. Thirtyfour
automatically sets the implicit wait to 30 seconds, but you can change it to whatever you need. You can also use CSS or XPath selectors to either wait for an element with specific attributes, or even wait for an existing element to gain specific attributes.
Hope that helps
from thirtyfour.
I tried this in python and it doesn't work there either.
Try this instead:
driver.execute_script("window.open('about:blank', '_blank');", &ScriptArgs::new()).await?;
let tabs = driver.window_handles().await?;
driver.switch_to().window(&tabs[1]).await?;
You can also replace the about:blank
with the url you want the new tab to navigate to.
from thirtyfour.
It work, thank for your help.
from thirtyfour.
Thank you,
-
How to set delay time when click or input element.
ex:
elem1.click().await?;
thread::sleep(time::Duration::from_secs(2)); //set delay time 2 second
elem2.click().await?; -
How to open New tab?
-
Add set time out to reload page?
from thirtyfour.
thank for your help, Can you tell me how to open a new tab with thirtyfour same here:
https://www.testingexcellence.com/open-new-tab-browser-using-selenium-webdriver-java/
from thirtyfour.
The code to open a new tab would be almost the same as the example you linked to.
Something like this (I have not tested it):
driver.find_element(By::Css("body")).await?.send_keys(Keys::Control + "t").await?;
let tabs = driver.window_handles().await?;
driver.switch_to().window(tabs[0]).await?;
You would need to check whether the new tab is the first element in the array.
Btw, feel free to browse the docs at https://docs.rs/thirtyfour. If anything is not clear in the docs I would be happy to update them.
from thirtyfour.
I had test with your code but don't work, it don't open new tab:
driver.find_element(By::Css("body")).await?.send_keys(Keys::Control + "t").await?;
from thirtyfour.
That will sent Ctrl+t to the body
element. It's possible that doesn't work on the page you are on. It might be worth trying the same in python or Java and seeing if that works.
from thirtyfour.
the code is worked, thank you.
from thirtyfour.
Related Issues (20)
- How use proxy in that library HOT 2
- When set_headless for chrome chrome=111.0.5563.146, cannot locate loginsubmit button HOT 2
- add_arg is not found within EdgeCapabilities HOT 2
- A workaround for drag_and_drop_element HOT 3
- javascriptEnabled is not the name of a known capability or extension capability HOT 1
- Can not to connect to remote webdriver. HOT 4
- 0.32 release, Potential segfault in the time crate HOT 1
- Deal with iframe, not working HOT 1
- Auto setup `chromedriver` and `geckodriver` HOT 2
- how to automatically run the webdriver before running the program? HOT 2
- Proxy doesn't work in Chrome. HOT 1
- so, how to get the text value of an element HOT 1
- 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
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.