Posts

Showing posts from July, 2019

Tooltip

Image
Tooltip shows title regarding to the the link we can get the information by getattribute of the element then we will get the information.

java programmes frequently asked in interview

1.print duplicate characters of the string? 2.check two string are anagram are not? 3. programme to count number of words in a string? 4.number of occurences of a given character in a string without loop? 5.reverse a string in 3 ways? 6.remove all white spaces from string? 7.find non repeated character from string? 8.reverse stringg using iteration and recursion? 9.string contains only digits are not? 10. reverse a string with preserving spaces psition ? (output:     illa purap udianivaR ) 11.reverse a each word of string ? 12.count no of vowels and consonants in a string? 13.. String to integer and integer to string? 14.All permutation of string ? 15.String is palindrome? 16.remove duplicate characters from string? 17.append astring to text file? 18.if string another string are not? 19.remove given characters from sring? 20.sort string in java? 21.nost repeatedwords in atext file? 22.first repeated character and non repeated character in a string? ...

java programmes Answers for the questions above.

1. Print duplicate characters from string? sol .          public  void  findduplicaearray() { String str="abbcccdddd"; Map<Character,Integer>mp=new HashMap<>(); Map<Character,Integer>dupl=new HashMap<>();         for(int i=0;i<str.length();i++){ if(mp.containsKey(str.charAt(i))){    int count=mp.get(str.charAt(i));                     count++;        mp.put(str.charAt(i),count);} else{ mp.put(str.charAt(i),1); } }         Set<Map.Entry<Character,Integer>>set=mp.entrySet();         for(Map.Entry<Character,Integer>st:set) {         if(st.getValue()>1) {         dupl.put(st.getKey(),st.getValue());                 }     ...

waits

implicitwait : implicit wait syntax is " driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);" and it is useful for every element which is opened by driver instance and if the element is not finded it will wait until the time we given explicitwait it is the wait which is useful for particular element which will take much time to load so that type of elements it will use webdriverwait wait=new webdriverwait( WebDriver reference ,20); wait.until(Expectedconditions.alert is present); so this is about explicit wait fluentwait: this is the wait whih is useful for the particular element which will take much time to load  so that it will take action for particular time and wait and again do the action and ignore the class Wait wait = new FluentWait(WebDriver reference) .withTimeout(timeout, SECONDS) .pollingEvery(timeout, SECONDS) .ignoring(Exception.class);

Actions

Actions action=new action(driver); clickAndHold() Clicks (without releasing) at the current mouse location. contextClick() Performs a context-click at the current mouse location. (Right Click Mouse Action) doubleClick() Performs a double-click at the current mouse location. dragAndDrop(source, target) Performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse. Parameters: source- element to emulate button down at. target- element to move to and release the mouse at. dragAndDropBy(source, x-offset, y-offset) Performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse. Parameters : source- element to emulate button down at. xOffset- horizontal move offset. yOffset- vertical move offset. keyDown(modifier_key) Performs a modifier key press. Does not release the modifier key - subsequent interactions may assume it's kept pressed. Parameters : modifier_key ...

Javascript executor uses

   Javascriptexecutor js=((javascriptexecutor)driver);     js.executescript(" window. scrollBy ( 100 ,  0 ) );******* to scroll horizontally     js.executescript(" scroll ( 100 ,  0 ) );   ***********to scroll     js.executescript("alert("i am ravi");");********* alert message     js.executescript("history.go(0)"); ************** to clear history     js.executescript("document.getelementbyid("").value("");");**********sendkeys     js.executescript("document.getelementbyid("").click();");     js.executescript("return document.title;").to string();     js.executescript("return document.url;").tostring();     js.executescript("window.location="------------"");");      js.executescript( ( "arguments[0].setAttribute('style', arguments[1]);" , element , "color: yellow; border: 2px solid yellow;" ); ); reusable code...

Sendkeys

This is one type of method preset in webdriver                     driver.findelements(by.id("yufuyj")).sendkeys("ftucvhjj"); javascriptexecutor js=((javascriptexecutor)driver);                   js.executescript(document.getelementbyid("").value="";"); actions action=new acions(driver);                   action.sendkeys(ele,"yufujhvjb");

Brokenlinks and images

The main difference between broken and non broken is the non broken is gives status code 200 List<WebElement>li=driver.findElements(By.tagName("a")); li.addAll(driver.findElements(By.tagName("img"))); System.out.println(li.size()); for(WebElement k:li) { if(!k.getText().isEmpty()) { connection=(HttpURLConnection) new URL(k.getAttribute("href")).openConnection(); connection.connect(); int code= connection.getResponseCode(); System.out.println(k.getText()+"---------------------"+code); } } connection.disconnect(); } 

Frames

Image
To find  frames first we need to dom structure and  search ctrl+f and tagname iframe and find size of the frames.  To test frames we use -------- http://demo.guru99.com/test/guru99home/ List<Webelement>li=driver.findelements(By.tagname("iframe")); systm.out.println(li.size());  frames can be handled by three ways namely      1.by id or name      2.by index      3.by element these type of frames we will find in interview first one is different and second one is different because in frame one we finded all the elements but in second inside inside inside frames are there

Alert

Image
There are 8 types of alerts       1. javascriptpopups       2.webpushnotifications       3.chatboot       4.Authntication popups       5.windows basedalerts       6.html light box       7. window popups     javascript popups : 1.simple popups  ::::  https://ksrtc.in/oprs-web/  ----- enter search button with out entering locations then you will find simle javascript alert   driver.get(" https://ksrtc.in/oprs-web/"); driver.findElement(By.xpath("//button[@class='btn btn-primary btn-lg btn-block btn-booking']")).click(); Thread.sleep(10000); Alert alert=driver.switchTo().alert(); System.out.println(alert.getText()); alert.accept();         2.sendsometextpopups alert.sendkeys("gyusvusf"); 3.warning popus                        ...