PHP Exception Handling with Finally

Malhar Lathkar
Updated on 18-Sep-2020 08:45:23

410 Views

IntroductionCode in finally block will always get executed whether there is an exception in ry block or not. This block appears either after catch block or instead of catch block.catch and finally blockIn following example, both catch and finally blocks are given. If execption occurs in try block, code in both is executed. If there is no exception, only finally block is executed.Example Live DemoOutputFollowing output is displayedCaught exception: Division by zero. This block is always executed Execution continueschange statement in try block so that no exception occursExample Live DemoOutputFollowing output is displayed2 This block is always executed Execution continuesfinally block onlyFollowing ... Read More

Check If an Alert Exists Using WebDriver

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:43:21

8K+ Views

We can check if an alert exists with Selenium webdriver. An alert is created with the help of Javascript. We shall use the explicit wait concept in synchronization to verify the presence of an alert.Let us consider the below alert and check its presence on the page. There is a condition called alertIsPresent which we will use to check for alerts. It shall wait for a specified amount of time for the alert after which it shall throw an exception.We need to import org.openqa.selenium.support.ui.ExpectedConditions and import org.openqa.selenium.support.ui.WebDriverWait to incorporate expected conditions and WebDriverWait class.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import ... Read More

Extending Exceptions in PHP

Malhar Lathkar
Updated on 18-Sep-2020 08:42:05

1K+ Views

IntroductionException class implements Throwable interface and is base class for all Exception classes, predefined exceptions as well as user defined exceptions. The Exception class defines some final (non-overridable) methods to implement those from Throwable interface, and __tostring() method that can be overridden to return a string representation of Exception object.final public function getMessage()message of exceptionfinal public function getCode()code of exceptionfinal public function getFile()source filenamefinal public function getLine()source linefinal public function getTrace()an array of the backtrace()final public function getPrevious()previous exceptionfinal public function getTraceAsString()formatted string of tracepublic function __toString()formatted string for displayIf user defined exception class re-defines the constructor, it should call parent::__construct() to ensure ... Read More

Select Drop-Down Menu Option Value with Selenium in Python

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:38:01

17K+ Views

We can select a drop-down menu option value with Selenium webdriver. The Select class in Selenium is used to handle drop-down. In an html document, the drop-down is identified with the tag.Let us see the html structure of a drop-down.For using the methods of Select class we have to import selenium.webdriver.support.select.Select in our code. Let us discuss the methods available to select an option from drop-down−select_by_visible_text (arg) – The arg which is passed as a parameter to the method is selected if it matches with the text which is visible in the dropdown.Syntax−sel = Select (driver.find_element_by_id ("name"))sel.select_by_visible_text ('Visible Text')select_by_value ... Read More

Get Text from Each Cell of an HTML Table Using Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:30:23

6K+ Views

We can get text from each cell of an HTML table with Selenium webdriver.A tag is used to define a table in an html document. A table consists of rows represented by and columns represented by . The table headers are identified by tag.Let us consider a table from which we will get text from each cell.AUTOMATION TOOLTYPELINNKSeleniumOpen Sourcehttps://www.selenium.org/UFTCommercialUNified Functional TesterRanorexCommercialhttps://www.ranorex.com/TestCompleteCommercialTest CoompleteLet us see the html code representation for the above table−To retrieve the rows count of the table, we will use−List rows =driver.findElements(By.tagName("tr"));int rws_cnt= rows.size();To retrieve the columns count of the table, we will use−List cols ... Read More

Get Entered Text from a Textbox in Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:06:50

19K+ Views

We can get the entered text from a textbox in Selenium webdriver. To obtain the value attribute of an element in the html document, we have to use the getAttribute() method. Then the value is passed as a parameter to the method.Let us consider a textbox where we entered some text and then want to get the entered text.If we spy on the element, we will find that there is no value attribute for this element in the html code.After entering text inside that field, we can get the entered text by using the getAttribute() method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ... Read More

Select iFrame Using Python and Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 08:00:45

5K+ Views

We can select iframe with Selenium webdriver. An iframe is identified with a tag in an html document. An iframe is an html document containing elements which resides inside another html document.Let us see a html document of a frame.The following methods help to switch between iframes−switch_to.frame(args) – The frame index is put as an argument to the method. The starting index of iframe is 0.Syntax−driver.switch_to.frame(0), switching to the first iframe.switch_to.frame(args) - The frame name or id is put as an argument to the method.Syntax−driver.switch_to.frame("nm"), switching to the iframe with name nm.switch_to.frame(args) - The frame webelement is put as ... Read More

Select Element Using XPath Syntax on Selenium for Python

Debomita Bhattacharjee
Updated on 18-Sep-2020 07:54:10

1K+ Views

We can select elements using xpath with Selenium webdriver. Xpath is one of the most important locators. There are two types of xpath. They are known as absolute [starting from parent node in DOM] and relative xpath [starting from anywhere in DOM].The xpath syntax is − //tagname[@attribute='value'] or //*[@attribute='value'].Let us consider the html code of an element that we shall identify with the help of xpath−The xpath expression is //input[@name='firstname'] or //*[@name='firstname'].Examplefrom selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm") // identify element with xpath l = driver.find_element_by_xpath("//input[@name='firstname']") l.send_keys("Python") driver.quit()OutputRead More

Get CSS Class Name Using Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 07:43:59

12K+ Views

We can get the css class name of an element with Selenium webdriver. To obtain the class name attribute of an element in the html document, we have to use the getAttribute() method. Then the class value is passed as a parameter to the method.Let us consider the below html code with class attribute.The class attribute is having the value as gsc-input. This can be obtained with the help of getAttribute() method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class GetClssAttribute{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = ... Read More

Delete Default Values in Text Field Using Selenium

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:56:36

14K+ Views

We can delete default values in the text field with Selenium webdriver. There are multiple ways to do this. We can use the clear() method which resets value present already in edit box or text area field.We can use the Keys.chord() method along with sendKeys(). The Keys.chord() method helps to press multiple keys simultaneously. It accepts the sequence of keys or strings as a parameter to the method.To delete default values, it takes, Keys.CONTROL, "a" as parameters. This string is then sent as a parameter to the sendKeys() method. Finally, we have to pass Keys.DELETE to the sendKeys() method.Let us consider ... Read More

Advertisements