for loop stops after 2nd case in Selenium - selenium

I am working on a script that should just refresh trades every 15 minutes. It worked well, but then I found a problem. When it finds the trade that has to be refreshed.
else if (text[2] == "hours" || text[2] == "hour" || text[2] == "days" ||
text[2] == "day" || text[2] == "month" || text[2] == "months" || x >= 15)
It goes into the trade, edits it and saves as it should. But right after that it stops working. It says the program is still running, but nothing happens anymore. I have no idea why it would not work as it works perfectly for this case:
if (text[2] == "seconds")
continue;
I can't find a reason for loop to stop working to be honest. Would appreciate any ideas or tips.
Code:
private void CheckItems(IWebDriver driver)
{
IList<IWebElement>
trades = driver.FindElements(By.ClassName("rlg-trade-display-header")); // add all trades to list
for (var i = 0; i <= trades.Count; i++) // loop to check all trades
{
driver.Navigate().GoToUrl(tradeUrl);
if (i == 0)
Console.WriteLine("Active Trades: " + trades.Count);
var text = driver
.FindElement(By.XPath(
"/html/body/main/div/div/div/div[4]/div[" + (i + 1) + "]/div[1]/div/div/span"))
.Text.Split(); // reads text from trade and adjust it for the program
Console.WriteLine("Trade " + (i + 1) + " was last updated " + text[1] + " " + text[2] + " ago.");
var x = int.Parse(text[1]); // convert string to int to check time later
if (text[2] == "seconds")
continue;
if (text[2] == "hours" || text[2] == "hour" || text[2] == "days" || text[2] == "day" ||
text[2] == "month" || text[2] == "months" || x >= 15)
{
var element1 =
driver.FindElement(By.XPath("/html/body/main/div/div/div/div[4]/div[" + (i + 1) +
"]/div[1]/a/div"));
var actions1 = new Actions(driver);
actions1.MoveToElement(element1).Click().Perform(); // scrolls down to choosen element and clicks it
driver.FindElement(By.XPath("/html/body/main/div/div/div/div[2]/a[1]"))
.Click(); // click choosen element
var element = driver.FindElement(By.Name("btnSubmit"));
var actions = new Actions(driver);
actions.MoveToElement(element).Click().Perform(); // scrolls down to choosen element and clicks it
Thread.Sleep(2000);
Console.ReadLine();
}
}
}
private static void Main(string[] args)
{
var bot = new Program();
bot.setup(bot.driver);
while (true)
{
bot.CheckItems(bot.driver);
Thread.Sleep(15000); // wait 15 second before next loop
}
}
What I found out is that when I put a Console.ReadLine() in main after bot.CheckItems(bot.driver); it will now refresh all the trades and print everything for one whole for loop and then it stops and doesn't continue. And if I keep it like in code I given higher it works perfectly if all trades are in no need for refresh but if even one is it will refresh it and stop working. Any ideas what might be a reason for that problem? And why Console.ReadLine() matters?

Related

Protecting rows depending on specific (today) date

I want to code my Google Sheets to check ("scan") active sheet to find a date that is "today" - and then, depending on the day, protect all columns in that row (row in witch it found todays date), so that only owner can change it (protect from everyone else).
With the help of the forum i found some "solutions", but cant get to make it work. I think there is a problem with for loop (just prediction).
Script should check for today date, read how many colmuns are active and lock the row(s) with today + all previous dates. I'm still missing the protection to lock all the rows with ownership rights only and ofcourse to work :)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('MY SHEET');
function lockRanges() {
var dateRange = ss.getRange(2, 1, ss.getLastRow()-2, 1);
var curDate = Utilities.formatDate(new Date(), "GMT+1", "dd/M/YYYY");
var val = dateRange.getDisplayValues();
var row;
var col;
var end = ss.getLastRow();
//Find last active column
for (var y = 0; y <= ss.getLastColumn(); y++) {
col = y + 1;
}
//Loop through all rows
for(var x = 0; x <= end; x++){
if(val[x][0]> curDate){
row = x;
break;
}
}
var protection = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE)
if(protection.length > 0){
var range = ss.getRange(2, 1, row, col);
protection[0].setRange(range);
}
else{
ss.getRange(2, 1, row, col).protect();
}
}

How to make a ToolStripMenuItem hold a variable value to be recalled later?

I have a form that has a MenuStrip at the top. I only have one ToolStripMenuItem called Dates. I have written code that executes when an "Add" button is clicked which adds a new menu item underneath "Dates". This menu item is named by concatenating some variables which store user input. Here is everything I have for the "Add" button click event. It all works, but I want display the same info that gets displayed in the label when the click event happens to be saved to the submenu item too. So I want to be able to click that sub-menu item that is created and be able to see what input was saved to it when the Add button is clicked.
private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e)
{
//add the input to the variables
String^ month = txtMonth->Text;
String^ day = txtDay->Text;
String^ year = txtYear->Text;
double tips = Double::Parse(txtTips->Text);
//make sure the date input is correct
if (txtMonth->Text == "" || txtDay->Text == "" || txtYear->Text == "" || Double::Parse(month) < 1 || Double::Parse(month) > 12
|| Double::Parse(day) < 1 || Double::Parse(day) > 31 /*|| Double::Parse(year)!=*/)
{
//show message box
MessageBox::Show("Please enter the date in the correct format.", "Error", MessageBoxButtons::OK,
MessageBoxIcon::Error);
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
}
else
{
//for the menu bar
String^ date = month + "/" + day + "/" + year;
datesToolStripMenuItem->DropDownItems->Add(date)->Equals(date);
//print to label
lblPrint->Text = month + "/" + day + "/" + year + " - " + tips.ToString("c");
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
txtTips->Clear();
}
}
FYI. I haven't written any code to do what I want to do. I just have no idea where to start for that, so I've shared what I have before that.

How Recycler View Holder.ItemView recycle

In my case , I got Exception
if (holder.isScrap() || holder.itemView.getParent() != null) {
throw new IllegalArgumentException(
"Scrapped or attached views may not be recycled. isScrap:"
+ holder.isScrap() + " isAttached:"
+ (holder.itemView.getParent() != null));
}
and holder.itemView.getParent() == true.
I do not use android:animateLayoutChanges and I donn't want use "setHasStableIds(true)" , but I don't know why holder.itemView.getParent is true. Maybe someone can give me a solution or a link, thx

PL/SQL - Aggregate values & Write to table

I am just starting to dabble in PL/SQL so this question may be very straightforward. Here is the scenario:
I have several checkboxes which carry a weighted numeric value. For example:
Checkbox I --> Value '5'
Checkbox II --> Value '10'
Checkbox III --> Value '15'
etc.
The form would have 15 checkboxes in total and the end-user can select anywhere from 0 to all 15. As they select the checkboxes, the total weight would get calculated and a final numeric value would be displayed. For example. checking off 3 Checkbox I & 2 Checkbox III would = 45 points.
Now the total value of 45 would equal to a separate value. Example:
At 0 points, value = 'Okay'
1-15 points, value = 'Error'
16-30 points, value = 'Warning'
31+ points, value = 'Critical'
The form itself is built within Oracle APEX and I can do it using Dynamic Actions but using PL/SQL may be a better solution.
In summary, I'd like the hidden field to first calculate the total from the checked checkboxes and then use that total to figure out the value of either Okay, Error, Warning, or Critical.
Any assistance is much appreciated!
In my experience, it is better if we're going to use javascript on your case since we have to manipulate DOM and events of the checkboxes. If you want to display/change item values and get values at runtime, then javascript is better in doing that than PLSQL unless you want to submit your page every time you check/uncheck a box in your page which is not advisable.
Here is my solution for your question.
First, create a Display Only item on your page. This is where the values "Okay", "Error", "Warning", or "Critical" will appear. And its very important to set it's default value to 0. Then inside your page's "Function and Global Declaration" part, put the following functions:
function getcheck(checkbox_id,displayOnly_id){
var chkboxName = document.getElementById(checkbox_id + "_0").getAttribute("name");
var chks = document.getElementsByName(chkboxName);
var howmanychecks = chks.length;
var currentSum=0;
var v_remarks = "";
for(x=0;x<howmanychecks;x++){
chks[x].setAttribute("onchange","checkIfchecked(this,\'" + displayOnly_id + "\')");
if(chks[x].checked){
currentSum = currentSum + Number(chks[x].value);
}
}
if(currentSum==0){
v_remarks = "Okay";
}
else if(currentSum>0 && currentSum<=15){
v_remarks = "Error";
}
else if(currentSum>15 && currentSum<=30){
v_remarks = "Warning";
}
else{
v_remarks = "Critical";
}
document.getElementById(displayOnly_id).value = currentSum;
document.getElementById(displayOnly_id + "_DISPLAY").innerHTML = currentSum + ": " + v_remarks;
}
function checkIfchecked(p_element, displayOnly_id){
var v_difference;
var v_sum = Number($v(displayOnly_id));
var displayOnly_display = displayOnly_id + "_DISPLAY";
var v_remarks = "";
if(p_element.checked){
v_sum = v_sum + Number(p_element.value);
$("#" + displayOnly_id).val(v_sum);
}
else{
v_difference=Number($("#" + displayOnly_id).val())-Number(p_element.value);
if(v_difference<0){
v_difference=0;
}
$("#" + displayOnly_id).val(v_difference);
}
if($("#" + displayOnly_id).val()==0){
v_remarks = "Okay";
}
else if($("#" + displayOnly_id).val()>0 && $("#" + displayOnly_id).val()<=15){
v_remarks = "Error";
}
else if($("#" + displayOnly_id).val()>15 && $("#" + displayOnly_id).val()<=30){
v_remarks = "Warning";
}
else{
v_remarks = "Critical";
}
document.getElementById(displayOnly_display).innerHTML=$("#" + displayOnly_id).val() + ": " + v_remarks;
}
The above functions will get the sum of the values of those boxes that are checked. A value of a box will be taken out of the current sum if it is unchecked as well. It will also display the remarks for the current checked points whether if it is "Okay", "Error", "Warning", or "Critical".
In your "Execute when Page Loads" part of your page, add the following line:
getcheck(nameofyourcheckboxitem,nameofyourdisplayonlyitem);
where nameofyourcheckboxitem is the name of your Check Box and nameofyourdisplayonlyitem is the name of the Display Only item you have just created.
Here's a sample line on how to use the function that I've given you:
getcheck("P1_MYCHECKBOX","P1_MYDISPLAYONLY");

AJAX filled pulldown shows 5 identical options when there are 5 different options in database

Scratching head here. I've got a pulldown and if I query it in SQL Server Manager Query Window I get 5 different values (these are sample points for a water system).
However, when the pulldown loads, there are 5 options of the first value. Can someone see something I can't?
I narrowed it down to the code below because I held my cursor over "results" which was the final step in my Controller's code, and it showed 5 items all of the same value:
else if ((sampletype == "P") || (sampletype == "T") || (sampletype == "C") || (sampletype == "A"))
{
var SamplePoints = (from c in _db.tblPWS_WSF_SPID_ISN_Lookup
where c.PWS == id && c.WSFStateCode.Substring(0, 1) == "S"
select c).ToList();
if (SamplePoints.Any())
{
var listItemsBig = SamplePoints.Select(p => new SelectListItem
{
Selected = false,
Text = p.WSFStateCode.ToString() + ":::" + p.SamplePointID.ToString(),
Value = p.WSFStateCode.ToString()
}).ToList();
results = new JsonResult { Data = listItemsBig };
}
}
return results ;
}
I have had a similar problem in nHibernate, it was caused by how I defined my primary keys/foreign keys in the ORM, leading to a bad join and duplicate values.