Struct Visibility in Rust Programming

Mukul Latiyan
Updated on 03-Apr-2021 13:31:24

1K+ Views

Structs in Rust contains an extra level of visibility. These can be modified by the developers as per his/her convenience.In a normal scenario, the visibility of the struct in Rust is private and it can be made public by making use of the pub modifier.It should be noted that this case of visibility only makes sense when we are trying to access the struct fields from outside the module, from where it is defined.When we are hiding the fields of the struct, we are simply trying to encapsulate the data.ExampleConsider the example shown below −mod my {    // A ... Read More

Result Type in Rust Programming

Mukul Latiyan
Updated on 03-Apr-2021 13:23:47

197 Views

There are two types of errors that occur in Rust, either a recoverable error or an unrecoverable error. We handle the unrecoverable errors with the help of panic!macro and the Result type along with others help in handling the recoverable errors.The Result type is a better version of the Option type which only describes the possible error instead of the possible absence.SignatureThe signature of Result Type is Result < T, E>and it can have only two outcomes.These are: Ok(T): An element T was found.Err(E): An error was found with an element E.Rust also provides different methods that we can associate with ... Read More

Program Arguments in Rust Programming

Mukul Latiyan
Updated on 03-Apr-2021 13:21:14

108 Views

Taking care of arguments passed at the runtime is one of the key features of any programming language.In Rust, we access these arguments with the help of std::env::args, which returns an iterator that gives us a string for each passed argument.ExampleConsider the example shown below −use std::env; fn main() {    let args: Vec = env::args().collect();    // The first argument is the path that was used to call the program.    println!("My current directory path is {}.", args[0]);    println!("I got {:?} arguments: {:?}.", args.len() - 1, &args[1..]); }We can pass arguments like this −./args 1 2 3 4 ... Read More

HashSet in Rust Programming

Mukul Latiyan
Updated on 03-Apr-2021 13:04:16

539 Views

Rust also provides us with a HashSet data structure that is mainly used when we want to make sure that no duplicate values are present in our data structure.If we try to insert a new value into a HashSet that is already present in it, then the previous value gets overwritten by the new value that we insertedBesides the key features, a HashSet is also used to do the following operations −union − Extract all the unique elements in both sets.difference −G ets all the elements that are present in the first set, but not in the second.intersection − Gets ... Read More

File Operations in Rust Programming

Mukul Latiyan
Updated on 03-Apr-2021 12:50:15

324 Views

File operations normally include I/O operations. Rust provides us with different methods to handle all these operations.OpenRust provides an open static method that we can use to open a file in read-only mode.ExampleConsider the code shown below:use std::fs::File; use std::io::prelude::*; use std::path::Path; fn main() {    // Create a path to the desired file    let path = Path::new("out.txt");    let display = path.display();    let mut file = match File::open(&path) {       Err(why) => panic!("unable to open {}: {}", display, why),       Ok(file) => file,    };    let mut s = String::new();    match ... Read More

Verify Color of a Web Element in Selenium WebDriver

Debomita Bhattacharjee
Updated on 03-Apr-2021 11:03:34

25K+ Views

We can verify the color of a webelement in Selenium webdriver using the getCssValue method and then pass color as a parameter to it. This returnsthe color in rgba() format.Next, we have to use the class Color to convert the rgba() format to Hex. Let us obtain the color an element highlighted in the below image. The corresponding color for the element is available under the Styles tab in Chrome browser.The color of the element is also provided in the hex code #797979.SyntaxWebElement t = driver.findElement(By.tagName("h1")); String s = t.getCssValue("color"); String c = Color.fromString(s).asHex();Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import ... Read More

Open Browser in Incognito Mode Using Python Selenium WebDriver

Debomita Bhattacharjee
Updated on 03-Apr-2021 11:00:57

8K+ Views

We can open a browser window in incognito/private mode with Selenium webdriver in Python using the ChromeOptions class. We have to create an object of the ChromeOptions class.Then apply the method add_argument to that object and pass the parameter -- incognito has a parameter. Finally, this information has to be passed to the webdriver object.Syntaxc = webdriver.ChromeOptions() c.add_argument("--incognito")Examplefrom selenium import webdriver #object of ChromeOptions class c = webdriver.ChromeOptions() #incognito parameter passed c.add_argument("--incognito") #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", options=c) driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/tutor_connect/index.php")OutputRead More

Capture Text from Alert Message in Selenium WebDriver

Debomita Bhattacharjee
Updated on 03-Apr-2021 11:00:34

3K+ Views

We can capture the text from the alert message in Selenium webdriverwith the help of the Alert interface. By default, the webdriver object has control over the main page, once an alert pop-up gets generated, we have to shift the webdriver focus from the main page to the alert.This is done with the help of the switchTo().alert() method. Once the driver focus is shifted, we can obtain the text of the pop-up with the help of the method switchTo().alert().getText(). Finally we shall use the accept method to accept the alert and dismiss method to dismiss it.Let us take an example ... Read More

Input Text in Text Box Without SendKeys Using Selenium

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:57:57

19K+ Views

We can input text in the text box without the method sendKeys with thehelp of the JavaScript Executor. Selenium executes JavaScript commands with the help of the executeScript method.The JavaScript command to be run is passed as parameter to the method. To enter text we shall first identify the input box with the JavaScript method document.getElementById. Then we have to apply the value method on it.Let us enter text Selenium in the below input box −SyntaxJavascriptExecutor j = (JavascriptExecutor)driver; j.executeScript ("document.getElementById('gsc-i-id1').value='Selenium'");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; public class JsEnterText{    public static void main(String[] ... Read More

Get All Options of a Dropdown Using Python Selenium WebDriver

Debomita Bhattacharjee
Updated on 03-Apr-2021 10:57:32

7K+ Views

We can obtain all options of a dropdown with Selenium webdriver inPython using the method options. It returns a list of the options in the dropdown.Then we have to use the method text, to get the option text.A dropdown is represented by select tag and its available options are represented by the tagname option. To handle dropdown in Selenium, we have to take the help of the Select class.Let us see the html code of a dropdown along with its options – By Subject and By Name.Syntaxl = driver.find_element_by_name("selType") d = Select(l)for opt in d.options -m = opt.textExamplefrom selenium import ... Read More

Advertisements