How to open a mail then delete it from gmail using webdriver? - webdriver

How to read email and then delete the email from Gmail inbox
Browser.findElement("//*[#id=':5']/descendant::div[#class='T-I J-J5-Ji nX T-I-ax7 T-I-Js-Gs ar7'][2]").click();

enter mail:
try {
Maildriver.findElement(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div[2]/div[1]/div[1]/div/div/div[7]/div/div[1]/div[2]/div/table/tbody/tr/td[4]/div[2]/span")).click();
} catch (Exception e) {
System.out.println(" Fail to find the mail and click it" ) ;
}
click at "link" that can be found inside the mail ( same you can do other stuff ).
try {
WebElement approveByMailLink = Maildriver.findElement(By.linkText("here")) ;
approveByMailLink.click() ;
} catch (Exception e) {
System.out.println(" Clicking the mail link (start your einstein account) failed" ) ;
}

System.setProperty("webdriver.firefox.marionette",System.getProperty("user.dir")+ "\\libs\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://accounts.google.com/ServiceLogin?");
UtilityMethods.sleep(5000);
driver.findElement(By.id("Email")).sendKeys("YourID");//Email ID
driver.findElement(By.id("next")).click();
UtilityMethods.sleep(5000);
driver.findElement(By.id("Passwd")).sendKeys("YourPassword");//Password
driver.findElement(By.id("signIn")).click();//Sign IN
UtilityMethods.sleep(20000);
System.out.println("Mail Opened");
UtilityMethods.sleep(20000);
System.out.println("Delete all check box is displayed :: "+driver.findElement(By.xpath("//div[#aria-label='Select']")).isDisplayed()+"");
System.out.println("Delete all check box is Enabled :: "+driver.findElement(By.xpath("//div[#aria-label='Select']")).isEnabled()+"");
driver.findElement(By.xpath("//div[#aria-label='Select']")).click();//Delete All Check BOX
UtilityMethods.sleep(20000);
System.out.println("Check box selected");
System.out.println("Delete button is displayed :: "+driver.findElement(By.xpath("//div[#aria-label='Delete']")).isDisplayed()+"");
System.out.println("Delete button is Enabled :: "+driver.findElement(By.xpath("//div[#aria-label='Delete']")).isEnabled()+"");
driver.findElement(By.xpath("//div[#aria-label='Delete']")).click();//Delete BUtton
UtilityMethods.sleep(20000);
System.out.println("Delete Button Clicked");

Related

Alert Message When TextField is empty (javafx)

I would like for my code to check if the textfields in my form are empty & then show a pop up alert message. My problem is, even if the textfields are filled in this alert message pops up as soon as I hit "ENTER" anyway. Any help is appreciated !
BtnEnter.setOnAction((ActionEvent e) -> {
if (txtfName.getText().isEmpty() | txtlName.getText().isEmpty() |
txtMI.getText().isEmpty() | txtStreeAdd.getText().isEmpty()
| txtCity.getText().isEmpty() | txtZip.getText().isEmpty()
| txtPhone.getText().isEmpty() | txtEmail.getText().isEmpty()
| txtSecEmail.getText().isEmpty()) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Warning");
alert.setHeaderText("Required Fields Empty");
alert.setContentText("The fields highlighted in red must be filled "
+ "out.\nPlease try again.");
alert.showAndWait();
I believe part of the issue may be using the single pipe | for OR instead of the standard ||.
However, there's another approach you could take that may be a little easier to read. This is how I handle validation in my applications:
public boolean validate() {
StringBuilder errors = new StringBuilder();
// Confirm mandatory fields are filled out
if (txtfName.getText().trim().isEmpty()) {
errors.append("- Please enter a first name.\n");
}
if (txtlName.getText().trim().isEmpty()) {
errors.append("- Please enter a last name.\n");
}
if (txtMI.getText().trim().isEmpty()) {
errors.append("- Please enter a middle initial.\n");
}
if (txtStreetAdd.getText().trim().isEmpty()) {
errors.append("- Please enter a street address.\n");
}
if (txtCity.getText().trim().isEmpty()) {
errors.append("- Please enter a city.\n");
}
if (txtZip.getText().trim().isEmpty()) {
errors.append("- Please enter a ZIP code.\n");
}
if (txtPhone.getText().trim().isEmpty()) {
errors.append("- Please enter a phone number.\n");
}
if (txtEmail.getText().trim().isEmpty()) {
errors.append("- Please enter a primary email address.\n");
}
if (txtSecEmail.getText().trim().isEmpty()) {
errors.append("- Please enter a secondary email address.\n");
}
// If any missing information is found, show the error messages and return false
if (errors.length() > 0) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Warning");
alert.setHeaderText("Required Fields Empty");
alert.setContentText(errors.toString());
alert.showAndWait();
return false;
}
// No errors
return true;
}
This has the added benefit of letting the user know exactly what information is missing as well. With this, you simply call the validate() method when the user clicks the action button. If validate() comes back true, you know you have all the information needed.
You can also approach it in this another way without Alert alert = new Alert(Alert.AlertType.WARNING); Here is a piece of code:
public boolean validateForm() {
StringBuilder errors = new StringBuilder();
// Confirm mandatory fields are filled out
if (jTextField1.getText().trim().isEmpty()) {
errors.append("- Please enter a first name.\n");
jTextField1.requestFocusInWindow();
JOptionPane.showMessageDialog(null, errors, "Warning!", JOptionPane.ERROR_MESSAGE);
return false;
}
if (jTextField2.getText().trim().isEmpty()) {
errors.append("- Please enter a last name.\n");
jTextField2.requestFocusInWindow();
JOptionPane.showMessageDialog(null, errors, "Warning!", JOptionPane.ERROR_MESSAGE);
return false;
}
String s = ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText();
if (s.equals("")) {
errors.append("- Please choose a date.\n");
jDateChooser1.requestFocusInWindow();
JOptionPane.showMessageDialog(null, errors, "Warning!", JOptionPane.ERROR_MESSAGE);
return false;
}
if (jTextField3.getText().trim().isEmpty()) {
errors.append("- Please enter the age.\n");
jTextField3.requestFocusInWindow();
JOptionPane.showMessageDialog(null, errors, "Warning!", JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
In this way, you can check if users know what exactly missing and show them an alert message. Add a listener for the button.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(validateForm()) {
System.out.println("First name: "+jTextField1.getText());
System.out.println("Last name: "+jTextField2.getText());
System.out.println("Date: "+jDateChooser1.getDate());
System.out.println("Age: "+jTextField3.getText());
}
}

org.openqa.selenium.ElementNotVisibleException: element not visible/Tried with ID as well as other combinations of CSS selector

boolean display=driver.findElement(By.cssSelector("input#txtkeyword[placeholder='Job title']")).isDisplayed();=false
boolean select=driver.findElement(By.cssSelector("input#txtkeyword[placeholder='Job title']")).isSelected();=false
boolean enable=driver.findElement(By.cssSelector("input#txtkeyword[placeholder='Job title']")).isEnabled();=true
There are many reasons for an element to not be visible. It could be covered by a pop-up, the DOM could still be loading, you may have to scroll it into view.
For the first instance, take a screenshot on failure and see if the element is covered. I use the following for cucumber-jvm. You can google how to do it for whatever framework you are using.
#After
public void captureScreenshotOnFailure(Scenario scenario){
try {
if (scenario.isFailed() && driver !=null) {
System.out.println("***>> Scenario failed: "+scenario.getStatus());
try {
driver augemented = new Augmenter().augment(webDriver);
byte[] screenshot = ((TakesScreenshot) augemented).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (Exception e) {
e.printStackTrace();
}
}
} finally {
if (driver !=null) {
driver.quit();
}
}
}
For the DOM not finished loading, wait for it.
Wait<driver> wait_element = new WebDriverWait(driver, 80);
WebElement jobTitleElement = wait_element.until(
ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
"input#txtkeyword[placeholder='Job title']")));
If the wait fails then the element just isn't there.
If the wait succeeds then scroll to the element. If the element was a button you could click() it after the moveToElement(). It is not but including the code just to be complete.
Actions action = new Actions(driver);
action.moveToElement(jobTitleElement).click().build().perform();

Put and Get Selected Radio Button from Radio Group using SharedPreferences

want to store selected radio from and radio group and once that fragment is again launch , previous selected radio should be selected , I tried but not able to get it .
I need to store selected position on Click of button only .
This is code which I am using :
radiogender=(RadioGroup)rootView.findViewById(R.id.radioGroup1);
radiogender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// find which radio button is selected
if(checkedId == R.id.radioButton1) {
Toast.makeText(getActivity(), "You: Dude !!!",
Toast.LENGTH_SHORT).show();
} else if(checkedId == R.id.radioButton2) {
Toast.makeText(getActivity(), "You: Babe !!!",
Toast.LENGTH_SHORT).show();
}
}
});
Try something like this
radiogender=(RadioGroup)rootView.findViewById(R.id.radioGroup1);
radioButton1=(RadioButton) rootView.findViewById(R.id.radioButton1);
radioButton2=(RadioButton) rootView.findViewById(R.id.radioButton2);
SharedPreferences myPrefs=context.getSharedPreferences("general",context.MODE_PRIVATE); //you can give any name in place of general to your preferences
radiogender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// find which radio button is selected
if(checkedId == R.id.radioButton1) {
Toast.makeText(getActivity(), "You: Dude !!!",
Toast.LENGTH_SHORT).show();
//save in preferences
myPrefs.edit().putInt("selected",1).commint();
} else if(checkedId == R.id.radioButton2) {
Toast.makeText(getActivity(), "You: Babe !!!",
Toast.LENGTH_SHORT).show();
//save in preferences
myPrefs.edit().putInt("selected",2).commit();
}
}
});
//check if there is any value in preferences and set accordingly
int s=myPrefs.getInt("selected",0); //will return 0 when nothing is stored
if(s==1){
radioButton1.setChecked(true);
} else if(s==2){
radioButton2.setChecked(true);
}
To add a value in preferences, you first use the edit() tag and then use putInt or putString ,etc. to add value to the preferences.
Example putInt("selected",1 ); Here the 'selected' is the key or name that you provide so that you can fetch the value with that key. And '1' is the value to be stored against that key.
Then use commit() to save the value in preferences.
When you need to fetch a value, you use getInt or getString etc. to fetch the value.
Example getInt("selected",0);. Here selected is the key whose value you want to fetch. 0 is the default value that will be supplied in case there is no value under the key that you have provided.
Hope this helps :)

Button Submit in Vaadin

I am Using Vaadin in my application to display the REPORTS on PAGED TABLE from date to to date.
The code is working fine, when I click the submit button the data is not showing any where on vaadin ui table but, when I click the header row of that table then the data is showing.I need when the user entered from date to to date then after clicking the submit button the I need to display the reports on table instead of clicking the header row.Here I am top display the reports on the table I am using PAGED TABLE instead of normal Table.
I am using this Code for all reports due to this all reports are behaving likesame.
Pls help me here is the code is
Button executeReportButton = new Button("Submit");
executeReportButton.addListener(new Button.ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
if ((Date) tatFromDate.getValue() != null
&& (Date) tatToDate.getValue() != null) {
runDBReport(reportTable, (Date) tatFromDate.getValue(),
(Date) tatToDate.getValue());
} else
showWarningNotification("Error loading check list report.",
"Date entered is not valid.");
}
});
private void runDBReport(PagedTable reportTable, Date fromDate, Date toDate) {
final PagedTable _reportTable = reportTable;
final Date _fromDate = fromDate;
final Date _toDate = toDate;
HibernateUtils.getCurrentSession().doWork(new Work() {
#Override
public void execute(Connection connection) throws SQLException {
String reportCall = "{ call RP_PROC_CHECKLIST_AUDIT(?, ?, ?) }";
CallableStatement stmt = null;
ResultSet rs = null;
try {
stmt = connection.prepareCall(reportCall);
// register the type of the out param - an Oracle specific
// type
stmt.registerOutParameter(3, OracleTypesHelper.INSTANCE
.getOracleCursorTypeSqlType());
// set the in param
stmt.setDate(1, new java.sql.Date(_fromDate.getTime()));
stmt.setDate(2, new java.sql.Date(_toDate.getTime()));
// execute and retrieve the result set
stmt.execute();
rs = (ResultSet) stmt.getObject(3);
// get the results
while (rs.next()) {
Object TATDataRowId = _reportTable.addItem();
_reportTable.getItem(TATDataRowId)
.getItemProperty("checklistid")
.setValue(rs.getString(1));
_reportTable.getItem(TATDataRowId)
.getItemProperty("checklistdescription")
.setValue(rs.getString(2));
// ... a trillion more
}
} catch (Exception e) {
logger.error(
"Error loading check list report. Exception: {}",
e.getMessage());
logger.debug("Error loading check list report.", e);
showWarningNotification(
"Error loading check list report. Please contact admin",
"Error message is : " + e.getMessage());
} finally {
rs.close();
stmt.close();
}
}
});
}
I think that your HibernateUtils.getCurrentSession().doWork(new Work().... is starting a background thread and, when the report is finished fills in the table.
For background threads updating the UI in vaadin, there a special rules on how to do it.
When you don't follow them, then the serverside changes are only visible on the next client->server interaction.
https://vaadin.com/book/vaadin7/-/page/advanced.push.html#advanced.push.running
Don't forget to also look at server push/polling, since the webbrowser must be notified for the new content

How to enable create / insert in a AxGridView in Enterprise Portal (Dynamics AX 2009)

There must be a way to enable creation and insertion of a record from a AxGridView without using the Tunnel and Wizard approach. From what I have found on the Internet so far, the only example is using a Wizard, and I honestly don't find that to be a user friendly approach.
Has anyone tried to enable insertion of records directly from a AxGridView?
Yes it is possible to enter data through AxGridView. Just enable Editing, deleting for that control. And one more thing to make new row - you have to make addditional button - create new line, and code behind:
protected void NewLine_Click(object sender, EventArgs e)
{
int editIdx = AxGridView1.EditIndex;
try
{
// Save the last unsaved line if any
if (AxGridView1.EditIndex != -1 && AxGridView1.Rows.Count > 0)
{
this.AxGridView1.UpdateRow(AxGridView1.EditIndex, true);
}
DataSetViewRow dsvr = this.dsv.AddNew();
}
catch (System.Exception ex)
{
AxExceptionCategory exceptionCategory;
if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
{
// Throw the fatal exception
throw;
}
if (exceptionCategory == AxExceptionCategory.NonFatal)
{
AxGridView1.EditIndex = editIdx;
}
}
}
private DataSetView dsv //get dataset view
{
get
{
DataSet dataSet = this.AxDataSource1.GetDataSet();
return dataSet.DataSetViews[this.AxGridView1.DataMember];
}
}

Resources