Select window unable to select Childwindow

In My JavaCode , After clicking on Edit Description link a window get opens (i.e. Java Script Window) Images here 1st one gives anchor tag with attributes and 2nd one is opened window

Image 1:: enter image description here

Image 2:: Window image Along with Page Source here
enter image description here

What i need is A. Select the window open(java script) B. Enter the text into Text Area and click Ok.

control is waiting infinite @ Select Window key word its not moving forward. I have to kill Control forcefully.

Here is the code

package Bala.AutoPratice.module1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class WindowSwitch {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub

        System.setProperty("webdriver.chrome.driver", "D:\bin\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        //driver.manage().window().maximize();
        driver.get("http://10.1.111.165/Login.aspx");
        //To check if we have landed in the correct place
        driver.findElement(By.id("LoginName")).sendKeys("User1");
        driver.findElement(By.id("Password")).sendKeys("User1@123");
        driver.findElement(By.id("LoginBtn")).click();

        driver.get("http://10.1.111.165/roles.aspx");
        driver.findElement(By.xpath("//*[@id="NewBtn"]/span")).click();

        driver.findElement(By.xpath("//*[@id="aspnetForm"]/table/tbody/tr[1]/td[2]/a")).click();

        String MainWindow=driver.getWindowHandle();
        Set<String> s1=driver.getWindowHandles();       
        Iterator<String> i1=s1.iterator();      

        while(i1.hasNext())         
        {       
            String ChildWindow=i1.next();       

            if(!MainWindow.equalsIgnoreCase(ChildWindow))           
            {           
                   // Switching to Child window
                    driver.switchTo().window(ChildWindow);  // HERE IT NEVER SELECTS                                                                                                           
                    driver.findElement(By.xpath("//*[@id="descript"]")).sendKeys("gadddn@gmail.com");                         
                    driver.findElement(By.xpath("//*[@id="myform"]/div/input[1]")).click();           

            // Closing the Child Window.
                        driver.close();     
            }       
        }       
        // Switching to Parent window i.e Main Window.
            driver.switchTo().window(MainWindow);   


        driver.quit();



    }



}

Print out a shape (square) with alternating rows of asteriks

I am trying to write a program that asks the user for row and column dimensions. (4×4 minimum & 10×10 maximum, but a combination like 4×8 is acceptable). In order to check if the numbers are in range, I have to use a while loop. The odd rows will be alternating *- of the length and
the even rows will be alternating —— of the length of the column. The only thing I am having trouble with is writing out the while loop and printing out the shape with the alternating rows.

Output should be this if user enters 4:

output

How Export jTabel to Excel Use Save As

I Have A Code To Export Mysql Data in jTabel to Excel (.xls), But While I Was Exporting When Clicking Export.

File Button Auto Save In The Locations That Have Been Specified In The Code .

So I Want Is When Clicking Button Export Specifies Storage Location As When Save As.

 public void export2 () { 
            try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/administrasi","root","");
        Statement statement = con.createStatement();

        FileOutputStream fileOut;
        // Hasil Export
        fileOut = new FileOutputStream("C:\Users\iyong\Documents.xls");
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("Sheet 0");

 // Nama Field
        Row row1 = worksheet.createRow((short)0);
        row1.createCell(0).setCellValue("No");
        row1.createCell(1).setCellValue("Tanggal");
        row1.createCell(2).setCellValue("Nopol");
        row1.createCell(3).setCellValue("Nama");
        row1.createCell(4).setCellValue("Jenis");
        row1.createCell(5).setCellValue("No Kartu");
        row1.createCell(6).setCellValue("No Kartu");
        row1.createCell(7).setCellValue("Realisasi");

        Row row2 ;
        ResultSet rs = statement.executeQuery("SELECT * FROM transaksi_tab");
        while(rs.next()){
            int a = rs.getRow();
            row2 = worksheet.createRow((short)a);
            // Sesuaikan dengan Jumlah Field
            row2.createCell(0).setCellValue(rs.getString(1));
            row2.createCell(1).setCellValue(rs.getString(2));
            row2.createCell(2).setCellValue(rs.getString(3));
            row2.createCell(3).setCellValue(rs.getString(4));
            row2.createCell(4).setCellValue(rs.getString(5));
            row2.createCell(5).setCellValue(rs.getString(6));
            row2.createCell(6).setCellValue(rs.getString(7));
            row2.createCell(7).setCellValue(rs.getString(8));
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
        rs.close();
        statement.close();
        con.close();
        System.out.println("Export Success");
    }catch(ClassNotFoundException e){
        System.out.println(e);
    }catch(SQLException ex){
        System.out.println(ex);
    }catch(IOException ioe){
        System.out.println(ioe);
    }
        }

Compile JavaScript function into a callable Java object?

Suppose I have come text that defines a valid JavaScript function, like so:

function sum(x, y) {
    return x + y
}

I want to be able to write Java code which compiles that text into a callable entity such that:

  • My Java code can discover the compiled entity is a function and not an arbitrary script.
  • My Java code can discover how many parameters the function has.
  • I can invoke the function from Java by providing data bindings for all of the parameters.

I was expecting the javax.script package to provide code that would accomplish this, but I can’t for the life of me see how. How would I write Java code to accomplish what I have described above.

invisible recaptcha bind to button for each click

I am using insvisible recaptcha on search button, it works for first click of search button and results are displayed on same form below the search button, after results are displayed i dont see the recpatcha icon for second time unless and until i refresh the page.
Is it possible to display recpatcha even after search results are displayed.I have to call it on each click, even if page is not refreshed.

detect Javascript libraries using Jsoup in Java

I know there are ways to detect libraries using JavaScript by checking if a library is a global variable or not window.Libraryname but this won’t work if the libraries do not register as a global variable and instead defined within a scope (a function) of that application.

But I am wondering is there way to detect all JavaScript libraries used in a webpage using Java and the Jsoup library? Perhaps parse the page and look for the <script> tag? or are there better approaches?

Create filter/search function on multiple tables with javascript

I’ve been able to follow the following tutorial that allows me to create a filter on 1 table.

https://www.w3schools.com/howto/howto_js_filter_table.asp
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_filter_table

I would like to be able to filter multiple tables for the same input.

So:

  • 1 input form
  • multiple definitions
  • same filter on all tables
  • show/hide on all tables if match

Would this be possible?

Best way to create readable Javascript in Java for adding to html page

I am using j2html to create render html pages via Java, if the html called any javascript function I was putting the Javascript into a separate .js file. However it seems sensible to only include functions is the main application javascript file if they are general purpose functions used by multiple pages. A function written specifically for one page shod be stored somewhere else, creating separate .js files for each page is an administrative nightmare so I want to put them into the html itself near the calling code.

I can do this easily enough, and below is an example created by copying function directly from .js file and wrapping within j2htmls script and rawHtml tags. My problem is that the Javascript code within my Java code is not as readable as it is when within the seperate js file.

Is there any way I can write it in a neater more readable way ?

private Tag artwork()
{
  return script(rawHtml("function artwork() {n" +
          "    n" +
          "    select   = document.getElementById('fsArtwork');n" +
          "    selected = select.options[select.selectedIndex].value;n" +
          "    if(selected==0)n" +
          "    {n" +
          "    tdocument.getElementById('saveArtworkFilename').disabled = true;n" +
          "    }n" +
          "    elsen" +
          "    {n" +
          "    tdocument.getElementById('saveArtworkFilename').disabled = false;n" +
          "    }n" +
          "}"));
}

Integer and float value multipication – JavaScript/Java [duplicate]

This question already has an answer here:

I have a code which calculates – (115/100)*2,835,000
My expected result is – 3,260,250 (this i got when i calculated manually)
But the javascript and java returns me 3260249.9999999995

Why it is returning a decimal value when the answer should not contain decimal?