PowerShell version 7 has introduced a few new null operators. They are as below.Null-Coalescing operator - ??Null Conditional Assignment Operators - ??=Null Conditional member access operators - ?. and ?[]a. Null-Coalescing operator - ??Null Coalescing operator ??evaluates the left-hand side condition or operand and if it is null then evaluates the right-hand side operand otherwise provides the value of the left-hand side operand.For example, Without the Null-Coalescing operator, we would have written a script like as shown below, $Name = $null if($Name -eq $null){"Name is Null"} Else {"PowerShell"}The above same condition can be written with the ?? operator.$name = $null ... Read More
IntroductionAlmost everything in a PHP script is an expression. Anything that has a value is an expression. In a typical assignment statement ($x=100), a literal value, a function or operands processed by operators is an expression, anything that appears to the right of assignment operator (=)Syntax$x=100; //100 is an expression $a=$b+$c; //b+$c is an expression $c=add($a, $b); //add($a, $b) is an expresson $val=sqrt(100); //sqrt(100) is an expression $var=$x!=$y; //$x!=$y is an expressionexpression with ++ and -- operatorsThese operators are called increment and decrement operators respectively. They are unary operators, needing just one operand and can be used in prefix or ... Read More
IntroductionThe goto statement is used to send flow of the program to a certain location in the code. The location is specified by a user defined label. Generally, goto statement comes in the script as a part of conditional expression such as if, else or case (in switch construct)Syntaxstatement1; statement2; if (expression) goto label1; statement3; label1: statement4;After statement2, if expression (as a part of if statement) is true, program flow is directed to label1. If it is not true, statement3 will get executed. Program continues in normal flow afterwards.In following example, If number input by user is even, program ... Read More
IntroductionConditional execution of one or more statements is a most important feature of any programming language. PHP provides this ability with its if, else and elseif statements. Primary usage of if statement is as follows −Syntaxif (expression) statement;The expression in front of if keyword is a logical expression, evaluated either to TRUE or FALSE. If its value is TRUE, statement in next line is executed, otherwise it is ignored. If there are more than one statements to be executed when the expression is TRUE, statements are grouped by using additional pair of curly brackets, if (expression){ statement1; ... Read More
The validateCount attribute in PowerShell function is to validate the length of an array, which means that you can pass the specific number of arguments into the parameter. In the below example we need array should contain a minimum 1 and maximum 4 values when we pass the values. For that, we will write the below script, Function ValidateArray { Param ( [ValidateCount(1, 3)] [String[]]$Animals ) return $PSBoundParameters }OutputPS C:\> ValidateArray -Animals Cow, Dog, Cat Key Value --- ----- Animals {Cow, Dog, Cat}The above output is valid but when we pass ... Read More
The ValidateScript attribute is to validate the script before entering inside the function. For example, let say you want to validate the path of the file, validate the remote computer connectivity, etc. We will take here remote server connectivity example.Without the ValidateScript attribute, we would have written the script as shown below.Function Check-RemoteServer { param ( [string]$Server ) if(Test-Connection -ComputerName $Server -Count 2 -Quiet -ErrorAction Ignore) { Write-Output "$server is reachable" } else { Write-Output "$Server is unreachable" } }OutputPS C:\> Check-RemoteServer -Server asde.asde asde.asde is ... Read More
The ValidateLength attribute in PowerShell is used to validate the length of the String. Generally how we write the command without the mentioned attribute is using the Length method and if/else condition for the string. For Example, Function ValidateStorageName { param ( [String]$StorageName ) if(($StorageName.Length -gt 3) -and ($StorageName.Length -lt 15)) { Write-Output "`nStorage Name validated" } else { Write-Output "`nStorage Name validation failed" } }Output−PS C:\> ValidateStorageName -StorageName Alpha Storage Name validated PS C:\> ValidateStorageName -StorageName CN Storage Name validation failedWith the ValidateLength attribute, else ... Read More
The ValidateSet attribute in PowerShell function is to validate the values entered from the set which means, it allows only specific values from the set. To understand better consider the below example, we have an array and we need to check if entered values are among array or not then we will use the below code.Function PetAnimalsCheck { param( [String]$Animal ) $Animals = "Cow", "Dog", "Cat", "Horse", "Camel", "Elephant" if($Animals -contains $Animal) { Write-Output "Animal is in the list of Pet Animals" } else { Write-Output ... Read More
Validation parameters are a set of rules that you define on the PowerShell variable and restrict users from entering some values and binding users to enter values in the specific domain. If there are not validation parameters the script would be lengthy. The ValidateRange attribute is one of them.ValidateRange AttributeThis parameter is to validate the specific range of numbers. For example, If we need users to enter a value between 5 and 100 and we simply write the script using the If/else statement as shown below.function AgeValidation { param( [int]$age ) if(($age -lt 5) ... Read More
We can get the href of elements found by partial link text with Selenium webdriver. First of all we need to identify the links with help of the find_elements_by_partial_link_text() method.Next to get hold of href of the links we have to use the get_attribute() method and then pass href as a parameter to the method.Let us identify the href attribute of links identified with partial link text Policy in the below page.Examplefrom selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #identify links with partial link text l= driver.find_elements_by_partial_link_text("Policy") #iterate links for i in l: #get href from get_attribute() print("Href value ... Read More