python selenium/unittest check whether value has changed - selenium

How come I get the same results for q1 and q2? It seems that q2 is overwritten by q1. Don't understand since they reference the same element but store its value in different variables at different points of time.
There is definitely a change after I do ic.click for the second time. When I solely run the second part it gives me the correct result.
def test_relation(self):
ic = self.driver.find_element_by_xpath("//select[#id='selectNumber']/option[2]")
ic.click()
q1 = self.driver.find_elements_by_xpath("//select[#class='quarterSelect form__multiselect']/option")
print(len(q1))
ic = self.driver.find_element_by_xpath("//select[#id='selectNumber']/option[1]")
ic.click()
q2 = self.driver.find_elements_by_xpath("//select[#class='quarterSelect form__multiselect']/option")
print(len(q2))

If you are expecting ic.click() to cause something to happen, then you need to wait for that change to happen before you can look for it's result. adding in a call to WebDriverWait().until() for something will probably help you.
Also, I notice that the code is printing len(q1) and len(q2). are you sure that their length is not the same, even though they may have different items in the list?

Related

Unable to overwrite a Column Value using Pandas

I'm planning to overwrite a Field value using pandas but that does not seem to work. Am i missing anything as part of the code below?
`for row_no in range(df.shape[0]):
rowIndex = df.index[row_no]
if re.search('Fex|Process|PIP|VIP|Generic|Mobility', df.loc[rowIndex].VPC_Sub_Cat, re.I):
print(df.loc[rowIndex].Headline)
print(df.loc[rowIndex].VPC_Sub_Cat)
print(df.loc[rowIndex].Final_Result)
df.loc[rowIndex].Final_Result = 0
print(df.loc[rowIndex].Final_Result)
break`
The output that I get after running this piece of code is:
This is the description of the issue...
VPC-Generic
1
1
Also can i achieve the same thing using a function and applying that on a data frame? kindly let me know.
df.loc[rowIndex].Final_Result is equals to (in most situation though...)
df.loc[rowIndex]['Final_Result']
This will cause a chained assignment (see here #Warning)
Whether a copy or a reference is returned for a setting operation, may depend on the context. This is sometimes called chained assignment and should be avoided. See Returning a View versus Copy.
And then from Returning a view versus a copy
But it turns out that assigning to the product of chained indexing has inherently unpredictable results.
So using df.loc[rowIndex, 'Final_Result'] to make sure that the value you assigned is view, not copy.

Pentaho/PDI: Increment a value automatically by one if a load-job (within a metajob) fails

in PDI I've got the following structure
0_Metajob
1_Load_1
1_Load_2
1_SimpleEvaluation
1_Mail
As of now
1_Load_1 and 1_Load_2 are independent of each other. The second one will run, irrespective of the success of the first one. That is okay, I want it that way!
Issue
I want to have a counter that is incremented by one every time one of the single loads fails, i.e. in my example the counter can take the values 0, 1 or 2.
What do I need it for? Customer will receive a mail at the end of the metajob. The aforementioned value determines the subject of the mail, i.e. 0=everything fine, 1=so-so, 2=load totally failed!
Why not mailing within every single the Load-Job? I do that but without attaching the log-file because it is usually non-finished. Therefore the log-file is mailed with the mail that is sent when the Metajob is finished.
Tried
"Set a variable". Thought I can simply increment it with adding a one in the value field, i.e. "${VariableName}+1". Of course, this step is implementened within a fail path of each Load-Job.
However, it didn't work.
Would anyone mind helping me? I would appreciate that!
Set Variable doesn't do calculations, you'll need a Javascript step for that.
Fortunately, variables can be also be set within the Javascript step. This bit of code should go into each of the steps you put in place of the Set Variable steps:
var i = parseInt(parent_job.getVariable("Counter"),0);
i = i + 1;
parent_job.setVariable("Counter",i);
true;
This bit of code gets the variable "Counter" from the parent job and converts it to int, since all Pentaho variables are strings. Then it increments it and sets the job variable again. The "true" at the end is to ensure that the javascript step reports success to the main job.
IMPORTANT: This works roughly as you would expect in a Job. It will NOT in a transformation!

When merging runs A,B in Timsort (in function merge_lo) it says "Must also have that ssa.keys[na-1] belongs at the end of the merge". Why?

A and B are adjacent runs on a stack, with A being the bottom and smaller run(If B were smaller merge_hi would be performing the merging but the same question applies there as well).I have been trying to figure why the last element of A MUST be bigger than the last element of B because I don't see how the run decomposition (or the rest of the algorithm) would ensure that condition. Also, in the same function the code seems to suggest that the first element of B is always smaller than the first element of A which I also don't understand why, but I'm guessing the answer to this question is tied to the answer of the first question.
In short, galloping is the reason. That's why we haven't seen it at first, because I thought gallop_{left,right} is called only from merge_{lo,hi}. But it isn't true. gallop_... are also called from merge_at, before merge_{lo,hi} are called, in order to find "Where does b start in a?" and "Where does a end in b?". Those calls (and subsequent code) change ssb (and its length nb), and also ssa and its length na, such that the invariant in the title is satisfied.
That is, the point is that A and B are not "adjacent runs on the runstack" as found in the original list to be sorted. Before calling merge_{lo,hi}, they are trimmed so that the condition in the title holds. That is, prior to A being merged with B, the elements of B greater than the last element of A are explicitly left out of consideration. In other words, "Must also have that ssa.keys[na-1] belongs at the end of the merge" is true not because of some special property of ssa.keys[na-1], but because we have defined "the end of the merge" in such a way. :-)
That also means that when you implement Timsort yourself, and you leave out the galloping, you must also leave out that optimization being talked about here, otherwise the code won't work right.

calling script_execute with a variable

I'm using GameMaker:Studio Pro and trying to execute a script stored in a variable as below:
script = close_dialog;
script_execute(script);
It doesn't work. It's obviously looking for a script named "script". Anyone know how I can accomplish this?
This question's quite old now, but in case anyone else ends up here via google (as I did), here's something I found that worked quite well and avoids the need for any extra data structures as reference:
scriptToCall = asset_get_index(scr_scriptName);
script_execute(scriptToCall);
The first line here creates the variable scriptToCall and then assigns to it Game Maker's internal ID number for the script you want to call. This allows script_execute to correctly find the script from the ID, which doesn't work if you try to pass it a string containing the script name.
I'm using this to define which scripts should be called in a particular situation from an included txt file, hence the need to convert a string into an addressable script ID!
You seem to have some confusion over how Game Maker works, so I will try to address this before I get around to the actual question.
GML is a rather simple-minded beast, it only knows two data types: strings and numbers. Everything else (objects, sprites, scripts, data structures, instances and so on) is represented with a number in your GML code.
For example, you might have an object called "Player" which has all kinds of fancy events, but to the code Player is just a constant number which you can (e.g.) print out with show_message(string(Player));
Now, the function script_execute(script) takes as argument the ID of the script that should be executed. That ID is just a normal number. script_execute will find the script with that ID in some internal table and then run the script.
In other words, instead of calling script_execute(close_dialog) you could just as well call script_execute(14) if you happened to know that the ID of close_dialog is 14 (although that is bad practice, since it make the code difficult to understand and brittle against ID changes).
Now it should be obvious that assigning the numeric value of close_dialog to a variable first and then calling script_execute on that variable is perfectly OK. In the end, script_execute only cares about the number that is passed, not about the name of the variable that this number comes from.
If you are thinking ahead a bit, you might wonder whether you need script_execute at all then, or if you could instead just do this:
script = close_dialog;
script();
In my opinion, it would be perfectly fine to allow this in the language, but it does not work - the function call operator actually does care about the name of the thing you try to call.
Now with that background out of the way, on to your actual question. If close_dialog is actually a script, your suggested code will work fine. If it is an extension function (or a built-in function -- I don't own Studio so what do I know) then it does not actually have an ID, and you can't call it with script_execute. In fact, you can't even assign close_dialog to a variable then because it does not have any value in GML -- all you can do with it then is call it. To work around this though, you could create a script (say, close_dialog_script which only calls close_dialog, which you can then use just as above.
Edit: Since it does not seem to work anyway, check whether you have a different resource by the name of close_dialog (perhaps a button sprite). This kind of conflict could mean that close_dialog gives you the ID of the sprite, not of the script, while calling the script directly would still work.
After much discussion on the forums, I ended up going with this method.
I wrote a script called script_id()
var sid;
sid = 6; //6 = scriptnotfound script :)
switch (argument0) {
case "load_room":
sid = 0;
break;
case "show_dialog":
sid = 1;
break;
case "close_dialog":
sid = 3;
break;
case "scrExample":
sid = 4;
break;
}
return sid;
So now I can call script_execute(script_id("close_dialog"));
I hate it, but it's better than keeping a spreadsheet... in my opinion.
There's also another way, with execute_string();
Should look like this:
execute_string(string(scriptName) + "();");

Using System.Diagnostics.PerformanceCounterCategory.GetInstanceNames

When I use System.Diagnostics.PerformanceCounterCategory.GetInstanceNames call, I always get 0 instances returned the first time. If I actually query for a counter value first (using perfmon) and then call GetInstanceNames, it works fine. Can someone provide some insight? Do I need to get a counter value first (in code) and then use the GetInstanceNames?
I found the answer. I added a call to System.Diagnostics.PerformanceCounterCategory.ReadCategory before trying GetInstances. That seems to fixed the issue I was seeing.