I'm working on an automation project right now which is to create an account on a specific site.
There are different set of rules that needs to be checked. There needs to be a set of data where some of the required fields are missing, the email address used to create on the account is already used on the system and the last set is where the account could be created. The general flow of the process is:
Run SeleniumRC
Get Data from ExcelFile
The Excel Data is composed of different sets.
Set A : Missing Required Fille
Set B : Email address is already used
Set B : Complete/Correct Data
Go the site.
Input all data.
If set A :
Then creation will not process.
It will provide output:
Row Number - Error
If set B :
Then creation will not process.
It will provide output:
Row Number - Error
If set C :
It will create account.
Provide Screenshot ounce login
Go back to step 2 until all rows found on the Excel File is completely checked.
Output will be placed on another Excel File
I am able to run the process however that is if I am using a flag for each entry in the Excel File. This does defeat the purpose of checking the creation process works as expected.
My Selenium Command goes like this:
public void test_CreateAccount() throws Exception {
//Some code to data from Excel Sheet
totalrows = s.getRows();
int i = 1;
while(i<totalrows){
//Some command to set data to string names
RowNum = s.getCell(0, i).getContents();
FName = s.getCell(1, i).getContents();
selenium.open // Go to a specific site
selenium.click("css=a > img"); // click create account
selenium.waitForPageToLoad("60000");
selenium.type("name=q1557", FName);
selenium.type("name=q1558", LName);
selenium.type("name=q1578", JobTitle);
selenium.type("name=q1579", email1);
selenium.type("name=email_confirm", email2);
selenium.type("name=q1583", phone);
selenium.type("name=q1584", ext);
selenium.type("name=q1585", fax);
selenium.type("name=q1587", company);
selenium.select("name=q1588", organization);
selenium.type("name=q1591", address1);
selenium.type("name=q1592", address2);
selenium.type("name=q1593", city);
selenium.select("name=q1594",state);
selenium.type("name=q1595", other);
selenium.type("name=q1598", zip);
selenium.select("name=q1596", country);
selenium.type("name=q1599", password1);
selenium.type("name=password_confirm", password2);
selenium.type("name=q1600", question);
selenium.type("name=q1601", answer);
selenium.click("name=submit_signup"); // click submit
i = i + 1;
}
}
When I run the command above, this does work. If data is SET A or B, then error occurred. If data is SET C, then it will create and then done.
In order to check all data within the Excel file or continue until end of totalrows, I placed a flag.
In the middle of the command I place something like
if(flag=1){ //input process only until submit button. }else
if(flag=2){ //input process only until submit button. }else{ create
}
I tried using try and catch with SeleniumException however it still does not work. Can you provide me with any idea on how to do this.
Related
I have multiple rows and columns which will be updated on a daily basis, and I want email to be triggered to mail id's taken from another column from the same sheet.
For example I have many email id's present in column C [can't mention a specific range since the data will be added everyday] and when values of column H are marked "Yes" then the mail id from the corresponding row in C column must be taken and email should be triggered to that id. I have tried multiple scripts but it's not working.
function onEdit(e) {
if(e.range.getSheet().getName()!='Sheet Name Used in this Operation') return;
if(e.range.columnStart==8 && e.value=="YES") {
//Send email
}
}
I'm not sure but I think you may need to create an installable trigger to send email.
Enable the Gmail service for your script
Go to your sheet and click Tools > Script editor
In the script editor, click Resources > Advanced Google Services... enable 'Gmail API' and click OK
Code
Copy & paste the following code (and make any modifications, if needed) to your sheet's script editor:
function sendEmail(dest, data) {
var messageBody = 'Hello, there has been a new release:\n\n' + JSON.stringify(data);
GmailApp.sendEmail(dest, 'Automated email from sheet', messageBody);
}
function onEditTrigger(e) {
var range = e.range;
if (range.columnStart == 8 && e.value == 'YES') {
// Prepare the email
var row = range.getSheet().getRange(e.range.rowStart, 1, 1, 8).getValues()[0];
var headers = range.getSheet().getRange(1, 1, 1, 8).getValues()[0];
var dest = row[1];
var data = {};
for (var i=0; i<8; i++) {
data[headers[i]] = row[i];
}
sendEmail(dest, data);
}
}
The code will get the 8 first columns of the row that has been modified and send them to the email specified in column B, along with the headers, as JSON format. You can see the spreadsheet I used for testing here. The email I received looks like the following:
Set the onEditTrigger function as an installable trigger
From the sheet's script editor, click the clock icon ("Current project's triggers")
Click the Add Trigger button
Choose the onEditTrigger function as the function to be ran, and On edit as the event type (example trigger configuration) and click save
Now every time the sheet gets modified the code above will run, and if appropriate, send the message.
I am programming an application in C# (Visual Studio 2015) and I need to update an .xlsm file.
This file has many formulas, over 1200 names and vba code.
I am using the Interop library and I am able to update some cells and get the relative updated formulas but i have some problem with the Names defined in the Excel.
The program recognizes the names in the Names collection but doesnt let me access some of the names.
When I try to access the value of the cell using its name it produces an exception.
I dont understand why i can access some of the names and others no.
Besides, in the excel, I can see the Name in the combo but when I select it, the cursor doesn't position over the cell.
In my program I could avoid this problem accessing the cells using the reference instead of the Name, but the vba in the excel uses the names and if i open the file from my app it doesnt work.
I am using this code:
excelApplication = new Microsoft.Office.Interop.Excel.Application();
excelApplication.ScreenUpdating = true;
excelApplication.Visible = true;
excelApplication.DisplayAlerts = false;
excelWorkbook = excelApplication.Workbooks.Open(txtFicheroEntrada.Text);
wsDatos = excelWorkbook.Worksheets[1];
wsDatos.Select();
foreach(Microsoft.Office.Interop.Excel.Name v in excelWorkbook.Names)
{
string NombreVar = v.Name;
//here i found the name BobinadoAT correctly. It exists
if (NombreVar == "BobinadoAT" ){ Console.WriteLine(NombreVar); }
}
if (wsDatos.Range["BobinadoAT"] != null) //but here this produces an exception
{
string valorcelda = wsDatos.Range["BobinadoAT"].Value.ToString();
}
¿does anyone work with many excel Names?
¿Am I accessing the names incorrectly?
I have a particular FolderID and I'd like to upload files to this directory. (I have the reference to the iManage.dll and ImanEXTLib).
I'm struggling with filling out certain fields in the dialog/import window from the code level.
Ideally, I would like to skip this stage to make the upload faster. If I'm conveying all the required data then I can't see any point in the dialog besides clicking OK.
This is the code:
I'm locating the folder by using ManDMS.CreateSearchParameters
After getting results:
Dim rslts as IManFolders
Set rslts = IManSession.WorkArea.SearchFolders(<ManStrings>,<SearchParameters>)
If rslts.Empty = True Then
MsgBox "Found shit."
Elseif rslts.Empty = False Then
Dim TgtFdr as ImanFolder
Set impCmd = ImportCmd
Set context = New ContextItems
Set TgtFdr = rslts.ItemByIndex(1)
Now I'm setting the context items but I have the problem with Matter and Subclass. These are obligatory for the upload but the fields remain empty and I don't know how to address them to complete the upload:
context.Add("IManDestinationObject", TgtFdr)
context.Add("IManExt.Import.DocAuthor", UserID)
context.Add("IManExt.Import.DocDescription", file Name)
context.Add("IManExt.Import.FileName", file path)
context.Add("IManExt.Import.DocClass", "some info")
context.Add("IManExt.Import.DocSubclass", "some info")
context.Add("IManExt.Import.DocMatter", "some info")
impCmd.Initialize context
impCmd.Update
If impCmd.Status = IMANEXTLib.CommandStatus.nrActiveCommand Then
impCmd.Execute
Else
Endif
Tried different things - MatterID, MatterDesc, Custom1,2,3,. Is it possible to skip the part with this window and upload the file in a more straightforwrd way? Also, is it possible to to take out the doc number of the newly imported file at the end?
I tried:
UplDoc = (ImanDocument)context.Item("ImportedDocument")
I figured the whole thing out.
Sort of... I went into the object browser and managed to go around the problem and take advantage of the .DuplicateProfileFromDoc method. I simply mirror the profile of the uploaded doc from other already stored on worksite.
The last bit also solved.
It should be:
Set UplDoc = context.Item("ImportedDocument")
Cheers!
After speaking to Google Enterprise Support they suggested I create a post on Stackoverflow.
I have a Google Doc sheet with a list of stores (sheet A) and I'm trying to reference another sheet (sheet B) to VOID specific stores.
What I'm going to accomplish is if a store name on the void sheet is entered into sheet A it will automatically convert the store name to VOID.
Google support believes an IF statement would be the beginning to the solution, they weren't able to help beyond this.
For anyone's time that comes up with a solution, I'd be happy to buy you a couple Starbucks coffees. Your support means a lot.
make it simple using Google Scripts. (Tutorial)
To edit scripts do: Tools -> Script Editor
and in the current add this function
EDIT:
Well, you need to make a trigger. In this case will be when the current sheet is edited
Here is the javascript
function onEdit(event) {
// get actual spreadsheet
var actual = event.source.getActiveSheet();
// Returns the active cell
var cellSheet1 = actual.getActiveCell();
// get actual range
var range = event.source.getActiveRange();
// get active spreadsheet
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// get sheets
var sheet_two = activeSpreadsheet.getSheetByName("Sheet2");
range.copyValuesToRange(sheet_two, range.getColumn(), range.getColumn(), range.getRow(), range.getRow());
// get cell from sheet2
var cell = sheet_two.getRange(range.getValue());
cell.setValue(cellSheet1.getValue());
// display log
Logger.log(cellSheet1.getValue());
}
if you want to test it you can check my spreadsheet, there you can check that all data thats is inserted in sheet1 will be copied to sheet2
I am creating Excel Sheet using Devexpress Exporter and then saving the file at a particular location.
After the creation of file, I have to open it, to add dropdownlist of items and then save it again in same location.
After all the operations, the file has to be emailed automatically to the email address from database.
Now if I have 1000 email addresses, and to automate this process, it is creating more than 10 instances of Excel.
How can I stop creation of those instance and how can I use excel operations without using more memory.
Code is as below:
protected string CreateExcelFile(string FilterName)
{
Random ranNumber = new Random();
int number = ranNumber.Next(0, 10000000);
string FileName = "TestDoc"+DateTime.Now.Year.ToString()+number.ToString()+DateTime.Now.Second.ToString()+".xls";
string path = #"c:\TestDocuments\"+FileName;
Directory.CreateDirectory(Path.GetDirectoryName(path));
FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
XlsExportOptions options = new XlsExportOptions();
options.ExportHyperlinks = false;
ASPxExporter.WriteXls(fs, options);
fs.Close();
AddDropDownToExcel(path);
return path;
}
//Adding The Dropdownlist Of Items TO Generated Excel Sheet
protected void AddDropDownToExcel(string path)
{
Microsoft.Office.Interop.Excel.Application application = new Microsoft.Office.Interop.Excel.Application();
string fileName = path.Replace("\\", "\\\\");
string RowCount = "F" + (testgrid.VisibleRowCount + 1).ToString();
// Open Excel and get first worksheet.
var workbook = application.Workbooks.Open(fileName);
var worksheet = workbook.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
// Set range for dropdownlist
var rangeNewStatus = worksheet.get_Range("F2", RowCount);
rangeNewStatus.ColumnWidth = 20;
rangeNewStatus.Validation.Add(Microsoft.Office.Interop.Excel.XlDVType.xlValidateList, Microsoft.Office.Interop.Excel.XlDVAlertStyle.xlValidAlertStop,
Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlBetween, "Item1,Item2,Item3,Item4");
// Save.
workbook.Save();
workbook.Close(Microsoft.Office.Interop.Excel.XlSaveAction.xlSaveChanges, Type.Missing, Type.Missing);
application.Quit();
}
First, I sincerely hope this isn't running on a server.
Then, if your problem is that too many instances of Excel are created, a thought is "don't create an instance every single time". Instead of starting Excel every time AddDropDownToExcel is called, can you reuse the same instance?
The problem you are having shows up regularly in Excel interop scenario; even though you are done and tell Excel to close, it "stays alive". It's usually caused by your app still holding a reference to a COM object that hasn't been disposed, preventing Excel from closing. This StackOverflow answer provides some pointers: https://stackoverflow.com/a/158752/114519
In general, to avoid that problem, you want to follow the "one-dot" rule. For instance, in your code:
var workbook = application.Workbooks.Open(fileName);
will be a problem, because an "anonymous" wrapper for Workbooks is created, and will likely not be disposed properly. The "one-dot" rule would say "don't use more than one dot when working with Excel interop", in this case:
var workbooks = application.Workbooks;
var workbook = workbooks.Open(fileName);
A totally different thought - instead of using Interop, can't you use OpenXML to generate your Excel file? I have never tried it to create drop downs, but if it supports it, it will be massively faster than Interop, and the type of problems you have won't happen.
Hope this helps.
As I know the grow of number of runnig excel.exe processes is 'normal' situation to excel :)
The dumbest advice is just kill sometimes it's processes. BUT, this way will be absolutely unhelpful if you use excel during your app is working because of you rather don't get which one excel.exe is yours.