I am new in Selenium webdriver.When i reading values from Excel sheet and saved to database.The values are not displaying in the webpage and also not inserted to Database.
Here this is my code for one form.If there any way for solving this issue.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.chrome.ChromeDriver;
public class DeliveryNote
{
public static void main(String[] args) throws InterruptedException, BiffException, IOException
{
//For ChromeBrowser
//System.setProperty("webdriver.chrome.driver", "E:/Softwares/Chrome/Chromedriver.exe");
//WebDriver driver = new ChromeDriver();
WebDriver driver = new FirefoxDriver();
//Puts a Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch website
driver.navigate().to("http://192.168.1.185:8080/Nayonika/loginPage.html");
//Maximize the browser
driver.manage().window().maximize();
// xpath of username
driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/p[1]/input")).sendKeys("aaa");
// xpath of password
driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/p[2]/input")).sendKeys("2222");
//xpath of checkbox
driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/p[3]/label/input")).click();
//xpath of login button
driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/p[4]/input")).click();
System.out.println(" Login Successfully.....");
//Puts a Implicit wait, Will wait for 20 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Navigate to sales
Actions actions = new Actions(driver);
//Xpath of Documents
WebElement Mainmenu = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/ul/ul/li[1]/a"));
//xpath of Sales
WebElement Submenu = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/ul/ul/li[1]/ul/li[2]/a"));
//xpath of Delivery Note
WebElement Childsubmenu = driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/ul/ul/li[1]/ul/li[2]/ul/li[5]/a"));
actions.moveToElement(Mainmenu).moveToElement(Submenu).moveToElement(Childsubmenu).click().build().perform();
Thread.sleep(5000);
//Specify the file path of the excelsheet
FileInputStream fi = new FileInputStream("D:\\7SYSERP\\deliverynote.xls");
Workbook W = Workbook.getWorkbook(fi);
//TO get the access to the sheet
Sheet s = W.getSheet(0);
// xpath of New Button
driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[2]/tr[2]/td/input[1]")).click();
for(int i = 4; i<= 5;i++)
{
// xpath of New Button
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[2]/tr[2]/td/input[1 ")).click();
//Puts a Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//xpath of StockDetail id
String stkdtlid = s.getCell(0,i).getContents();
System.out.println("StockDetail id" + stkdtlid);
// driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[1]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[1]/input")).sendKeys(stkdtlid);
//driver.findElement(By.id("1196")).clear();
driver.findElement(By.id("1196")).sendKeys(stkdtlid);
System.out.println("StockDetail id1" + stkdtlid);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//xpath of Delivery Note Detail Remarks
String remarks = s.getCell(1,i).getContents();
System.out.println("Delivery Note Detail Remarks" +remarks);
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[2]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[2]/input")).sendKeys(remarks);
//driver.findElement(By.id("287")).clear();
driver.findElement(By.id("287")).sendKeys(remarks);
System.out.println("Delivery Note Detail Remarks 1" +remarks);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// xpath of Delivery Note Details Status id
String delntdtlstatusid = s.getCell(2,i).getContents();
System.out.println("Delivery Note Details Status id" +delntdtlstatusid);
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[3]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[3]/input")).sendKeys(delntdtlstatusid);
//driver.findElement(By.id("286")).clear();
driver.findElement(By.id("286")).sendKeys(delntdtlstatusid);
System.out.println("Delivery Note Details Status id 1" +delntdtlstatusid);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//xpath of Quantity
String qty = s.getCell(3,i).getContents();
System.out.println("Quantity " +qty );
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[4]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[4]/input")).sendKeys(qty );
//driver.findElement(By.id("285")).clear();
driver.findElement(By.id("285")).sendKeys(qty);
System.out.println("Quantity 1" +qty );
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//xpath of Unit id
String untitid = s.getCell(4,i).getContents();
System.out.println("Unit id" +untitid);
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[5]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[5]/input")).sendKeys(untitid);
//driver.findElement(By.id("284")).clear();
driver.findElement(By.id("284")).sendKeys(untitid);
System.out.println("Unit id 1" +untitid);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//xpath of Item id
String itemid = s.getCell(5,i).getContents();
System.out.println("Item id " + itemid);
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[6]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[6]/input")).sendKeys(itemid);
//driver.findElement(By.id("283")).clear();
driver.findElement(By.id("283")).sendKeys(itemid);
System.out.println("Item id 1 " + itemid);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// xpath of Delivery Note id
String delvrynteid = s.getCell(6,i).getContents();
System.out.println("Delivery Note id" +delvrynteid);
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[7]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[7]/input")).sendKeys(delvrynteid);
//driver.findElement(By.id("282")).clear();
driver.findElement(By.id("282")).sendKeys(delvrynteid);
System.out.println("Delivery Note id 1" +delvrynteid);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// xpath of Delivery Note Detail id
String delvryntedtlid = s.getCell(7,i).getContents();
System.out.println("Delivery Note Detail id " +delvryntedtlid);
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[8]/input")).clear();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[8]/input")).sendKeys(delvryntedtlid);
//driver.findElement(By.id("281")).clear();
driver.findElement(By.id("281")).sendKeys(delvryntedtlid);
System.out.println("Delivery Note Detail id 1 " +delvryntedtlid);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// xpath of Save
driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div/table[1]/tr[2]/td[9]/input[1]")).click();
System.out.println("Saved");
}
driver.close();
}
}
Related
I have to print the hotel name and price side by side
example: oyo Rooms - 2000rs
I tried to use the Selenium web driver.
WebDriver driver = new ChromeDriver();
String baseUrl = "https:www.teletextholidays.co.uk";
driver.get(baseUrl);
driver.manage().window().maximize();
WebElement all_Inclusive = driver.findElement(By.xpath("//*[#class='header pstn-fxd edge txt-center fixed-nav-container']//div[#class='show-on-desktop inblock']//a[#class='top-nav-allinclusive nav-item txt-white inblock hover-out allinclusivelink']"));
all_Inclusive.click(); WebElement all_hotels =driver.findElement(By.xpath("//*[#class='lg-flex-box']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", all_hotels);
List<WebElement> hotellist = driver.findElements(By.xpath("//*[#class='deal-price pstn-reltv grid-stay items-center space-between']//span[#class='dstn-name txt-bold']"));
System.out.println(hotellist.get);
List<WebElement> pricelist = driver.findElements(By.xpath("//*[#class='deal-price pstn-reltv grid-stay items-center space-between']//span[#class='tth-price font-bold txt-sunset']" ));
/*for (WebElement hotel : hotellist) {
System.out.println(hotel.getText());
}*/
for (WebElement price : pricelist) {
System.out.println(price.getText());
if(price.getText().contains("157")) {
System.out.println(hotel);
}
}
Expected output: Oyo - 1000, alpha - 2345.
What am I doing wrongly?
We need to fetch parent elements first and then find hotel and price from that elements to keep co-relation b/w them.
Try the following code to print hotel - price format.
List<WebElement> listOfLinks = driver.findElements(By.cssSelector("a>div.deal-price"));
for(WebElement link: listOfLinks) {
System.out.print(link.findElement(By.cssSelector(".from-price>.dstn-name")).getText());
System.out.print(" - ");
System.out.println(link.findElement(By.cssSelector(".txt-right .tth-price")).getText());
}
I'm running Windows 10 virtual machine on ubuntu, and on VM I have following versions :-
Eclipse neon, Selenium Webdriver 3.0.1, Mozilla Firefox 51.0.1, Google Chrome 55, geckoDriver v0.11.1, Chromedriver v2.27, BrowserMob Proxy jar 2.1.4, jackson-all-1.7.3.jar, harlib-1.1.2.jar
I wanted to read browser traffics in selenium and for that i opted for BrowserMob proxy. I have 2 page of communication on the browser like Authenticates url, Lands on the 1st page clicks a dropdown menu (link) and lands on the 2nd page
When the second page opens the page does not load but the calls are going behind. What i noticed is in the VM when the second page loads internet connectivity goes off at that page only (internet sign stops blinking).
When i Reboot both the VM & the host machine and then execute the code. It loads the page at first attempt after fresh reboot of the system then again, if i execute the same code same problem persists.
But the traffic data is getting logged in the file. The same code if i try to execute in geckodriver(Firefox) then the page is getting loaded but traffic is not getting captured.capturing only specific urls from the log data
I have stuck in both the ways. Please find below the code :-
class 1 :-
public class BrowserMobExample{
public static String sFileName = System.getProperty("user.dir") + "\\CaptureNetworkTraffic\\BrowserMob.har";
WebDriver driver = null;
BrowserMobProxy proxy = null;
#BeforeTest
public void setUp() throws Exception {
// start the proxy
proxy = new BrowserMobProxyServer();
proxy.start(0);
//get the Selenium proxy object - org.openqa.selenium.Proxy;
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
//set chromedriver system property
System.setProperty("webdriver.chrome.driver", "path to chromedriver");
driver = new ChromeDriver(capabilities);
/*System.setProperty("webdriver.gecko.driver", "path to geckodriver");
driver = new FirefoxDriver(capabilities);*/
// enable more detailed HAR capture, if desired (see CaptureType for the complete list)
proxy.enableHarCaptureTypes(CaptureType.REQUEST_HEADERS, CaptureType.RESPONSE_HEADERS);
proxy.newHar("label_for_har");
driver.manage().window().maximize();
driver.get("http://username:pswd#url.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Robot rb = new Robot();
rb.keyPress(KeyEvent.VK_ENTER);
//do something on page
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement citySelect = driver.findElement(By.xpath("dropdown_xpath"));
Select dropdown= new Select(select_a_dropdown_menuitem);
dropdown.selectByVisibleText("Text_displayed");
//driver.navigate().refresh();
}
#Test
public void testCaseOne() throws AWTException {
/*driver.manage().window().maximize();
driver.get("http://username:pswd#url.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Robot rb = new Robot();
rb.keyPress(KeyEvent.VK_ENTER);
//do something on page
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement citySelect = driver.findElement(By.xpath("dropdown_xpath"));
Select dropdown= new Select(select_a_dropdown_menuitem);
dropdown.selectByVisibleText("Text_displayed");
//driver.navigate().refresh();*/
}
#AfterTest
public void tearDown() {
// get the HAR data
Har har = proxy.getHar();
// Write HAR Data in a File
File harFile = new File(sFileName);
try {
har.writeTo(harFile);
ReadHAR reading = new ReadHAR();
reading.main(null);
} catch (IOException ex) {
System.out.println (ex.toString());
System.out.println("Could not find file " + sFileName);
}
/*if (driver != null) {
proxy.stop();
//driver.quit();
}*/
}
}
class 2 :-
public class ReadHAR {
public static void main(String[] args) {
String filename = new String();
filename = BrowserMobExample.sFileName;
// System.out.println("This is the file location " + filename);
File f = new File(filename);
HarFileReader r = new HarFileReader();
HarFileWriter w = new HarFileWriter();
try
{
System.out.println("Reading " + filename);
HarLog log = r.readHarFile(f);
// Access all elements as objects
HarBrowser browser = log.getBrowser();
HarEntries entries = log.getEntries();
// Used for loops
List<HarPage> pages = log.getPages().getPages();
List<HarEntry> hentry = entries.getEntries();
String string1 = "p_still_media";
String string2 = "m_still_media";
String string3 = "T-Map";
/* for (HarPage page : pages)
{
System.out.println("page start time: "
+ ISO8601DateFormatter.format(page.getStartedDateTime()));
System.out.println("page id: " + page.getId());
System.out.println("page title: " + page.getTitle());
}*/
File varTmpDir = new File(System.getProperty("user.dir") + "\\CaptureNetworkTraffic\\results.txt");
boolean exists = varTmpDir.exists();
System.out.println(" result.txt : " +exists);
System.out.println(" file path:"+ varTmpDir);
if(exists){
varTmpDir.delete();
}
File result = new File(System.getProperty("user.dir") + "\\CaptureNetworkTraffic\\results.txt");
// result.createNewFile();
result.setWritable(true);
//FileWriter fw = new FileWriter(result, false);
// PrintWriter out = new PrintWriter(fw);
//Output "response" code of entries.
for (HarEntry entry : hentry)
{
// System.out.println("IP is : " + entry.getServerIPAddress());
if(entry.getRequest().getUrl().contains(string2)/* & entry.getResponse().getStatus() !=200*/){
System.out.println(" Url is : " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus()); //Output url of request
// Files.newBufferedWriter(result, StandardOpenOption.APPEND);
// out.write(" Url is : " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus());
// BufferedWriter bw = new BufferedWriter(fw);
System.out.println("IP is :- "+entry.getServerIPAddress());
FileWriter fw = new FileWriter(result, true);
BufferedWriter out = new BufferedWriter(fw);
out.write(" Url is : " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus());
out.newLine();
out.close();
fw.close();
}
else if(entry.getRequest().getUrl().contains(string3) /*& entry.getResponse().getStatus() !=200*/){
// System.out.println("request code: " + entry.getRequest().getMethod()); //Output request type
System.out.println(" Url is: " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus()); //Output url of request
// out.write(" Url is : " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus());
FileWriter fw = new FileWriter(result, true);
BufferedWriter out = new BufferedWriter(fw);
out.write(" Url is : " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus());
out.newLine();
out.close();
fw.close();
}
else if(entry.getRequest().getUrl().contains(string1) /*& entry.getResponse().getStatus() !=200*/){
// System.out.println("request code: " + entry.getRequest().getMethod()); //Output request type
System.out.println(" Url is: " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus()); //Output url of request
//out.write(" Url is : " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus());
// out.close();
//System.out.println(" response code: " + entry.getResponse().getStatus()); // Output the
FileWriter fw = new FileWriter(result, true);
BufferedWriter out = new BufferedWriter(fw);
out.write(" Url is : " + entry.getRequest().getUrl() + " response code: " + entry.getResponse().getStatus());
out.newLine();
out.close();
fw.close();
}
}
/*
// Once you are done manipulating the objects, write back to a file
System.out.println("Writing " + "fileName" + ".test");
File f2 = new File("fileName" + ".test");
w.writeHarFile(log, f2);
*/
}
catch (JsonParseException e)
{
e.printStackTrace();
//fail("Parsing error during test");
}
catch (IOException e)
{
e.printStackTrace();
//fail("IO exception during test");
}
}
}
With ChromeDriver logs are getting generated but the page is not loading. With firefox page is loading but logs are not captured (I think for geckodriver browsermob proxy is not compatible or this feature isn't available yet)
Am i missing anything or what is the issue ? Stuck on this since more than a week. Tried the above on ubuntu to but facing the same issue.
Any help on this issue is much appreciated.
I tried to add attachment in ics file but it not showing in outlook when open it. I am trying to add attachment like when we send meeting request and add attachment in that from outlook, that attachment can view from calendar as well. This is my ics file :
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//appform.com//NONSGML kigkonsult.se iCalcreator 2.18//
METHOD:PUBLISH
X-WR-TIMEZONE:UTC
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
UID:20160719T144014-694839744#appform.com
DTSTAMP:20160719T124014Z
ATTACH;FMTTYPE="application/msword; charset=binary";FILENAME=1468827330fCrj
O.doc:/var/www/html/basearch.appform.com/application/../public/uploads/146
8827330fCrjO.doc
ATTENDEE;RSVP=TRUE;SENT-BY="MAILTO:sajal#mailinator.com";CN=satyendra#hirest
orm.com;DIR="/var/www/html/app/application/../public/uplo
ads/1468827330fCrjO.doc";LANGUAGE=us-EN;X-AGENDA=Interview;X-LENGTH=30 min
:MAILTO:satyendra#mailinator.com
DESCRIPTION:Name: Dean Nestle Jones G\nVacancy: test\nEmployer: Zend\nDate:
Wednesday\, 20thJuly 2016\nTime: 1430 to 1500\n\nSubmit Feedback : http:/
/hirestorm.com/tms/a/Mg==/appid/NDU4/vacid/MTY4/candid/MTY=\n\nCandida
te CV : https://f12b1a775b358d1fc463-637e94f874af614e321f6.ssl.
cf2.rackcdn.com/1468827330fCrjO.doc\nOther Documents : https://f12b1a775
b358d1fc463-637e94f874af614cdn.com/146297361
8PwEwE.jpeg\n
DTSTART:20160720T090000Z
DTEND:20160720T093000Z
LOCATION:1 2 Elmshorn Schleswig-Holstein Germany
SEQUENCE:0
SUMMARY:New Interview Confirmed: Dean Nestle Jones G for test
BEGIN:VALARM
ACTION:PROCEDURE
DESCRIPTION:Name: Dean Nestle Jones G\nVacancy: test\nEmployer: Zend\nDate:
Wednesday\, 20thJuly 2016\nTime: 1430 to 1500\n\nSubmit Feedback : http:/
/hirestorm.com/tms/a/Mg==/appid/NDU4/vacid/MTY4/candid/MTY=\n\nCandida
te CV : https://f12b1a775b358d1fc463-637e94f874af614ce048a5e321d7d0f6.ssl.
cf2.rackcdn.com/1468827330fCrjO.doc\nOther Documents : https://f12b1a775
b358d1fc463-637e94f874af614ce048a5e32cdn.com/146297361
8PwEwE.jpeg\n
TRIGGER:-PT0H15M0S
END:VALARM
END:VEVENT
END:VCALENDAR
Your iCalendar file contains a reference to :
/var/www/html/basearch.appform.com/application/../public/uploads/1468827330fCrjO.doc
This would obviously be something on your machine. You're not embedding any file, you're just pasting a local path. Unless you have Outlook running on linux there's no way it can find that path.
I tried to do it in a simple java
import java.io.IOException;
import java.net.URI;
import java.text.ParseException;
import java.util.HashMap;
import javax.activation.DataHandler;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
import com.tba.readProps.Constants;
import com.tba.readProps.ReadProps;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.Period;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.parameter.Cn;
import net.fortuna.ical4j.model.parameter.Role;
import net.fortuna.ical4j.model.property.Attendee;
import net.fortuna.ical4j.model.property.CalScale;
import net.fortuna.ical4j.model.property.ProdId;
import net.fortuna.ical4j.model.property.Uid;
import net.fortuna.ical4j.model.property.Version;
import net.fortuna.ical4j.util.RandomUidGenerator;
import net.fortuna.ical4j.util.UidGenerator;
public class EmailWithCalendar{
/**
* #param emailAddr
* #param subject
* #param message
*/
public static void sendHtmlEmail(String emailAddr, String subject, String message){
HashMap propertyValues = null;
String smtpHost = "";
try {
propertyValues = ReadProps.initializeProperties();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
smtpHost = (String) propertyValues.get(Constants.SMTP_HOST);
//ManagerPropertiesBean mgrProps = new ManagerPropertiesBean();
//String smtpHost = mgrProps.getMgrProperty("smtpHost");
try {
// start a session with given properties
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", smtpHost);
Session mailSession = Session.getDefaultInstance(props, null);
String fromAddress = null;
fromAddress = (String) propertyValues.get(Constants.FROM_ADDRESS);
if(!"undefined".equals(fromAddress)){
InternetAddress fromAddr = new InternetAddress("test#test.com");
InternetAddress toAddr = new InternetAddress(emailAddr);
MimeMessage myMessage = new MimeMessage(mailSession);
String replyToAddress = null;
replyToAddress = (String) propertyValues.get(Constants.REPLY_ADDRESS);
InternetAddress replyToAddr[] = new InternetAddress[1];
if(!"undefined".equals(replyToAddress))
replyToAddr[0] = new InternetAddress(replyToAddress);
boolean isfromValid = true;
boolean isToValid = true;
boolean emailDomainCheck = true;
MimeBodyPart messageBodyPart =new MimeBodyPart();
messageBodyPart.setContent(message ,"text/html" );
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
myMessage.setContent(multipart);
if(emailDomainCheck==true)
{
myMessage.addRecipient(javax.mail.Message.RecipientType.TO, toAddr);
myMessage.setReplyTo(replyToAddr);
}
else
{
myMessage.setFrom(fromAddr);
myMessage.addRecipient(javax.mail.Message.RecipientType.TO, toAddr);
if(!"undefined".equals(replyToAddress))
myMessage.setReplyTo(replyToAddr);
}
myMessage.setSentDate(new java.util.Date());
myMessage.setSubject(subject);
messageBodyPart.setDataHandler(new DataHandler(
new ByteArrayDataSource(createEvent().toString(), "text/calendar")));// very important
//myMessage.setText(message);
// now send the message!
if(emailDomainCheck==true)
{
if(isfromValid==true && isToValid==true)
{
Transport.send(myMessage);
}
}
else
{
Transport.send(myMessage);
}
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error occurred in ManagerEmailBean.sendHtmlEmail()");
}
}
private static Calendar createEvent() throws ParseException {
// Create the event
String eventName = "Progress Meeting";
//DateTime start = new DateTime(startDate.getTime());
//DateTime end = new DateTime(endDate.getTime());
// Create the date range which is desired.
DateTime start = new DateTime("20100101T070000Z");
DateTime end = new DateTime("20100201T070000Z");;
Period period = new Period(start, end);
VEvent meeting = new VEvent(start, end, eventName);
// add timezone info..
//meeting.getProperties().add(tz.getTimeZoneId());
// generate unique identifier..
UidGenerator ug = new RandomUidGenerator();
Uid uid = ug.generateUid();
meeting.getProperties().add(uid);
// add attendees..
Attendee dev1 = new Attendee(URI.create("mailto:dev1#test.com"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);
Attendee dev2 = new Attendee(URI.create("mailto:dev2#test.com"));
dev2.getParameters().add(Role.OPT_PARTICIPANT);
dev2.getParameters().add(new Cn("Developer 2"));
meeting.getProperties().add(dev2);
// Create a calendar
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(Version.VERSION_2_0);
icsCalendar.getProperties().add(CalScale.GREGORIAN);
// Add the event and print
icsCalendar.getComponents().add(meeting);
System.out.println(icsCalendar);
return icsCalendar;
}
public static void main(String[] args) {
sendHtmlEmail("dev.test#gmail.com", "Test", "sjgsfgsf<p>dshdfsdf</p>");
}
}
I am finding difficult to enter the user name and password present on the iframe which gets popped up when we click on the signin link.
Can somebody help me on this.
Site link given below
link : http://cashkaro.iamsavings.co.uk/
With Regards,
There is a predefined method exists in Selenium which you can use to switch to a Frame or an IFrame.
WebDriver driver = new FirefoxDriver();
There are 3 overloaded methods which you can use to switch to a frame.
1. driver.switchTo().frame(String frameId);
2. driver.switchTo().frame(int frameNumber);
3. driver.switchTo().frame(WebElement frame);
You can either of the above 3 methods to switch on a frame.
Hope it helps!
For the switch to an iframe, you can use:
public void switchToFrame(WebElement element) {
getDriver().switchTo().frame(element);
}
or
wati.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By locator)
wati.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(WebElement element)
To work with iframe you must switch from your current page to iframe.
Try the below code and let me know your result.
WebDriver driver = new FirefoxDriver();
driver.get("http://cashkaro.iamsavings.co.uk/");
String linkText = "SIGN IN";
WebElement eventElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.linkText(linkText)));
eventElement.click();
WebElement frame = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.xpath("html/body/div[14]/div[1]/div[2]/div[2]/div[1]/iframe")));
driver.switchTo().frame(frame);
driver.findElement(By.id("uname")).sendKeys("username#domain.com");
driver.findElement(By.id("uname")).sendKeys(Keys.TAB);
driver.findElement(By.id("pwd")).sendKeys("enteryourpassword");
driver.findElement(By.id("sign_in")).click();
Use your valid login credentials to sign in.
Please find the answer below
public void login_normally() {
navigate_to_url(prop.getProperty("url_prod_Locale"));
// Parent window
String parent_window = driver.getWindowHandle();
System.out.println("Parent windiow :" + parent_window);
driver.findElement(By.xpath(prop.getProperty("singin_link"))).click();
WebDriverWait wait = new WebDriverWait(driver, 7);
String iframe_xpath = prop.getProperty("iframe_com_xpath");
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By
.xpath(iframe_xpath)));
driver.findElement(By.xpath(prop.getProperty("email_id_InSignIn")))
.sendKeys(prop.getProperty("user_email_id_signIn"));
driver.findElement(By.cssSelector(prop.getProperty("password_InSign")))
.sendKeys(prop.getProperty("pwd_signIn"));
boolean check_box_flag = driver.findElement(
By.xpath(prop.getProperty("Keep_me_signed_in"))).isSelected();
System.out.println("check_box_flag" + check_box_flag);
if (check_box_flag == false) {
driver.findElement(By.xpath(prop.getProperty("Keep_me_signed_in")))
.click();
}
driver.findElement(By.xpath(prop.getProperty("sign_button_signIn")))
.click();
//=================================================================================
/* String login_mesg_error = driver.findElement(
By.cssSelector(prop.getProperty("loginerror"))).getText();
System.out.println(" login Error : " + login_mesg_error);
if (login_mesg_error.length()<0 ) {
System.out.println("Sucessfully Loggedin");
Assert.assertTrue(true, "Sucessfull Login");
APPLICATION_LOG.debug(login_mesg_error);
} else {
System.out.println("Login Failed");
Assert.assertTrue(false, login_mesg_error);
APPLICATION_LOG.debug(login_mesg_error);
}*/
//==============================================================================
String login_mesg_error=" ";
List<WebElement> li=driver.findElements(By.cssSelector(prop.getProperty("logout_button_css")));
System.out.println(" list size :" +li.size());
if(li.size()>0)
{
System.out.println("Sucessfully Loggedin");
Assert.assertTrue(true, "Sucessfull Login");
APPLICATION_LOG.debug("Sucessfull Login");
} else {
login_mesg_error = driver.findElement(
By.xpath(prop.getProperty("login_error_mesg"))).getText();
System.out.println(" login Error : " + login_mesg_error);
System.out.println("Login Failed");
Assert.assertTrue(false, "Login failed - Incorrect username or password");
APPLICATION_LOG.debug(login_mesg_error + "Login failed");
}
driver.switchTo().defaultContent();
}
plz correct me :
driver.navigate().to(appURL);
System.out.println("Testing Login Page");
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Log In")));
WebElement logIN = driver.findElement(By.linkText("Log In"));
logIN.click();
WebElement username = driver.findElement(By.name("name"));
username.clear();
username.sendKeys("admin#cg.com");
WebElement password = driver.findElement(By.name("password"));
password.clear();
password.sendKeys("1234");
WebElement submitBtn = driver.findElement(By.id("login"));
submitBtn.click();
WebDriverWait wait1 = new WebDriverWait(driver, 60);
wait1.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[6]/div/div[2]/div/div[2]/div/ul/li[1]/div/div[1]/img")));
driver.findElement(By.xpath("/html/body/div[6]/div/div[2]/div/div[2]/div/ul/li[1]/div/div[1]/img")).click();
driver.navigate().back();