Привет, я пытаюсь получить текущий URl страницы, который должен быть сформирован как формат таблицы в почте, а почту нужно отправить получателям.
Я написал код, мне нужночтобы получить URL-адрес, сгенерированный в цикле for, и вставить его в почту в виде таблицы
Мне нужно перестроить код? цикл.
Есть ли другой способ выполнить это?
public class Mail extends JFrame {
public static String start = "<html>\n" +
"<head>\n" +
"<style>\n" +
"table, th, td {\n" +
" border: 1px solid black;\n" +
" border-collapse: collapse;\n" +
"}\n" +
"</style>\n" +
"</head>\n" +
"<body>\n" +
"Hi,<br>";
public static String htmlMsg ="";
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Mail frame = new Mail();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Mail() {
htmlMsg = htmlMsg.concat("<br><br>Mobile TestRail Links <br>"+
" <table style=\"width:100%\">\n" +
" <tr bgcolor=\"#F83911\">\n" +
" <th>Locale</th>\n" +
" <th>TestRail Link</th>\n" +
" </tr>\n");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 512, 263);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("zzz:");
lblNewLabel.setBounds(10, 11, 104, 20);
contentPane.add(lblNewLabel);
JComboBox comboBox = new JComboBox();
comboBox.addItem("abc");
comboBox.addItem("cde");
comboBox.setBounds(124, 11, 331, 20);
contentPane.add(comboBox);
JLabel lblNewLabel_1 = new JLabel("1");
lblNewLabel_1.setBounds(10, 53, 79, 34);
contentPane.add(lblNewLabel_1);
List<JCheckBox> locales = new ArrayList<JCheckBox>();
JCheckBox chckbxNewCheckBox = new JCheckBox("ram");
chckbxNewCheckBox.setBounds(17, 94, 63, 23);
contentPane.add(chckbxNewCheckBox);
locales.add(chckbxNewCheckBox);
JCheckBox chckbxNewCheckBox_1 = new JCheckBox("john");
chckbxNewCheckBox_1.setBounds(104, 94, 63, 23);
contentPane.add(chckbxNewCheckBox_1);
locales.add(chckbxNewCheckBox_1);
JCheckBox chckbxNewCheckBox_2 = new JCheckBox("man");
chckbxNewCheckBox_2.setBounds(177, 94, 72, 23);
contentPane.add(chckbxNewCheckBox_2);
locales.add(chckbxNewCheckBox_2);
JCheckBox chckbxNewCheckBox_3 = new JCheckBox("boy");
chckbxNewCheckBox_3.setBounds(17, 133, 63, 23);
contentPane.add(chckbxNewCheckBox_3);
locales.add(chckbxNewCheckBox_3);
JCheckBox chckbxNewCheckBox_4 = new JCheckBox("qwe");
chckbxNewCheckBox_4.setBounds(104, 133, 63, 23);
contentPane.add(chckbxNewCheckBox_4);
locales.add(chckbxNewCheckBox_4);
JCheckBox chckbxNewCheckBox_5 = new JCheckBox("asd");
chckbxNewCheckBox_5.setBounds(177, 133, 72, 23);
contentPane.add(chckbxNewCheckBox_5);
locales.add(chckbxNewCheckBox_5);
JCheckBox chckbxNewCheckBox_6 = new JCheckBox("987");
chckbxNewCheckBox_6.setBounds(17, 174, 63, 23);
contentPane.add(chckbxNewCheckBox_6);
locales.add(chckbxNewCheckBox_6);
JCheckBox chckbxNewCheckBox_7 = new JCheckBox("321");
chckbxNewCheckBox_7.setBounds(104, 174, 63, 23);
contentPane.add(chckbxNewCheckBox_7);
locales.add(chckbxNewCheckBox_7);
JCheckBox chckbxNewCheckBox_8 = new JCheckBox("qwe");
chckbxNewCheckBox_8.setBounds(177, 174, 72, 23);
contentPane.add(chckbxNewCheckBox_8);
locales.add(chckbxNewCheckBox_8);
JButton btnNewButton = new JButton("qweert");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(comboBox.getSelectedItem().equals("abc"))
{
System.setProperty("webdriver.chrome.driver","call from path");
WebDriver aru=new ChromeDriver();
aru.manage().window().maximize();
aru.get("https://example.com");
//Login
aru.findElement(By.id("name")).sendKeys("zzz");
aru.findElement(By.id("password")).sendKeys("yyy");
aru.findElement(By.id("button_primary")).click(); //Login
//aru.findElement(By.xpath("//*[@id=\"button_primary\"]/span")).click();
//aru.findElement(By.className("loginpage-button-sso-disable loginpage-button-sso-disable-hover loginpage-button-sso-disable-active")).click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(JCheckBox checkbox : locales)
{
if(checkbox.isSelected())
{
aru.get("xyz.com");
aru.findElement(By.xpath("//*[@id=\"suite-22496\"]/div[2]/div[1]/a")).click();
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
aru.findElement(By.xpath("//*[@id=\"content-header\"]/div/div[2]/a[1]")).click();
aru.findElement(By.xpath("//*[@id=\"includeSpecific\"]")).click();
aru.findElement(By.xpath("//*[@id=\"includeSpecificInfo\"]/a")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
aru.findElement(By.xpath("//*[@id=\"selectCasesNode-744350\"]/input")).click();
aru.findElement(By.id("selectCasesSubmit")).click();
aru.findElement(By.id("name")).clear();
DateFormat today = new SimpleDateFormat("MM/dd/yyyy ");
Date palani = new Date();
String content= today.format(palani);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
aru.findElement(By.id("name")).sendKeys("aaa" + checkbox.getText() + " - "+content);
//Mail text locales
htmlMsg = htmlMsg.concat(
" <tr>\n" +
" <td align=\"center\">" + checkbox.getText() + "</td>\n" +
" <td align=\"center\">" + aru.getCurrentUrl()+ "</td>\n" +
" </tr>\n");
htmlMsg = htmlMsg.concat("</table><br><br>\n");
}
else
{
}
}
}
else
{
JOptionPane.showMessageDialog(null, "Please select from list");
}
}
});
btnNewButton.setBounds(285, 122, 169, 34);
contentPane.add(btnNewButton);
}
public static void se(String msg) throws AddressException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.example.com");
Session session = Session.getDefaultInstance(props);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("syz@gmail.com"));
message.addRecipients(Message.RecipientType.TO, InternetAddress.parse("abc@gmail.com"));
message.setSubject("Vurrent URlLinks");
msg = start + msg +
"<br>Note: This is an automated email , please don't reply to this email. "
"</body>\n" +
"</html>";
System.out.println(msg);
message.setContent(msg, "text/html");
Transport.send(message);
System.out.println("=====Email Sent=====");
} catch (MessagingException e) {}}
}