Showing posts with label Selenium Interview Question 6. Show all posts
Showing posts with label Selenium Interview Question 6. Show all posts

Selenium Interview Question 6

·         15 : How To Handle Dynamic Changing IDs In XPath. 
Example : //div[@id='post-body-3647323225296998740']/div[1]/form[1]/input[1]
In this XPath "3647323225296998740" Is changing every time when reloading the page. How to handle this situation?
·        
Answer
 : There are many different alternatives In such case.

Alternative 1 : Look for any other attribute which Is not changing every time In that div node like name, class etc. So If this div node has class attribute then we can write xpath as bellow.

·         //div[@class='post-body entry-content']/div[1]/form[1]/input[1]
·        
Alternative 2 : You can use absolute xpath(full xpath) where you not need to give any attribute names In xpath.

·         /html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/div[2]/div[1]/form[1]/input[1]
·        
Alternative 3 : Use starts-with function. In this xpath's ID attribute, "post-body-" part remain same every time. So you can use xpath as bellow.

·         //div[starts-with(@id,'post-body-')]/div[1]/form[1]/input[1]
·        
Alternative 4 : Use contains function. Same way you can use contains function as bellow.

·         div[contains(@id,'post-body-')]/div[1]/form[1]/input[1]


16 : How to press ENTER key button on text box In selenium webdriver?
Answer : To press ENTER key using selenium WebDriver software automation tool, We need to use selenium Enum Keys with Its constant ENTER as bellow.

driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys(Keys.ENTER);

17 :
 How many types of waits available In selenium WebDriver
Answer : There are two types of waits available In selenium WebDriver software automation testing tool.
1.   Implicit Wait
2.   Explicit Wait
VIEW TUTORIALS on Implicit and Explicit Waits with practical examples detailed description.

18 : What Is Implicit Wait In Selenium WebDriver?
Answer : Sometimes, Elements are taking time to be appear on software web application page. Using Implicit wait In webdriver software testing test case, We can poll the DOM for certain amount of time when some element or elements are not available Immediately on webpage.

Implicit Wait Example :

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
If you will write above syntax In your test, Your WebDriver test will wait 10 seconds for appearing element on page.
19 : What Is Explicit Wait In Selenium WebDriver?
Answer : Using explicit wait code In selenium webdriver software automation testing tool, You can define to wait for a certain condition to occur before proceeding further test code execution.

Explicit Wait Example :

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gbqfq']")));
Above code will wait for 20 seconds for targeted element to be displayed and enabled or we can say clickable.
20 : I wants to pause my test execution for fix 10 seconds at specific point. How can I do It?
Answer : You can use java.lang.Thread.sleep(long milliseconds) method to pause the software test execution for specific time. If you wants to pause your test execution for 10 seconds then you can use bellow given syntax In your test.

Thread.sleep(10000);

21 : How does selenium RC software testing tool drive the browser? 
Answer :
When browser loaded In Selenium RC, It ‘injected’ javascript functions into the browser and then It Is using javascript to drive the browser for software application under test.
22 : How does the selenium WebDriver drive the browser?
Answer : Selenium webdriver software testing tool works like real user Interacting with software web page and Its elements. It Is using each browser's native support to make direct calls with browser for your software application under test. There Is not any Intermediate thing In selenium webdriver to Interact with web browsers.

Handling Dynamic Elements in Selenium WebDriver

                       Handling Dynamic Elements in Selenium WebDriver Dynamic elements are those elements which have identifiers that a...