Selenium Iterate Hidden Element - python-3.x

I have a few elements I want to click with selenium. The elements are hidden and I'm using the format right. Consequently, I'm looking for a workaround to iterate the function. I have the function in curly braces with the 'f' format to read the function. In order to see the element I have to switch the format to 'u'. The 'u' format only allows you to find hidden elements. Unfortunately, it does not read functions within curly braces. Which makes things more difficult to change the value within the variable. Also, there is no way to use both 'u' and 'f'. My question is if there is a workaround to achieve this task.
browser.find_element(By.XPATH, f"/html/body/app-root/ac-site-layout/div[{number}]")
error - cannot locate element
browser.find_element(By.XPATH, u"/html/body/app-root/ac-site-layout/div[{number}]")
error - can only hold one argument

Related

Using the replace function in Netsuite for components in assemblies

Very new to Netsuite. I'm trying to use a saved item search to find all instances of {componentitem} entry is 800484 and replace them with component 516551302688
I'm using the REPLACE function in the saved item search but it doesn't like my formula REPLACE(800484, [, 516551302688]){componentitem}
I'm sure I am doing something wrong in the formula but unsure what it is.
The function signature for REPLACE is:
REPLACE(char, search_string, replacement_string)
char is the text to search in.
search_string is the text to search for.
replacement_string is the text to replace the search_string with, where found.
What you have appears to be more like
REPLACE(search_string, replacement_string)char
The text you want to search in is outside of the function altogether (outside the parentheses that enclose what the function will act on). You also have additional brackets and a comma in your formula.
Based you the information in your question, your formula should be
REPLACE({componentitem}, '800484', '516551302688')
I have wrapped the search and replacement strings in quotes as REPLACE deals with strings. If you leave the quotes off, the database will infer the string values of the numbers given and it will still work, but it's best practice to be explicit.
Note that this will only replace the values within the results of the saved search, and will have no effect on the underlying records. Hopefully you already know this, but I just mention it as the wording of your question makes it appear as if you're expecting it to substitute the actual components.
HTH.

Xpath explanation

Hello i want to ask what exactly this Xpath does if we use.
I understand that it selects all b nodes that appear before the current node and that are not the same with current node.
//b[not(preceding::*=.)]
So if xml is like:
<a>
<b>English</b>
<b>German</b>
<b>Italian</b>
<b>Belarusian</b>
<b>Russian</b>
<b>Bulgarian</b>
<b>French</b>
<b>English</b>
</a>
Does this keep the last occurrence of the node or the first? this is what i do not get.
I was thinking that it should keep the last but using this xpath in FILTERXML function i gives the result of keeping the first occurrence so the result was
{"English";"German";"Italian";"Belarusian";"Russian";"Bulgarian";"French"}
Can someone explain?
This XPath,
//b[not(preceding::*=.)]
selects all b elements that do not have a preceding element with the same string value.
One might use this XPath to select only the first such elements, eliminating later "duplicates."
Notes:
To limit the scope to preceding b elements, use //b[not(preceding::b=.)].
To limit the scope to preceding b sibling elements, use //b[not(preceding-sibling::b=.)]
It means "select all b nodes for which there doesn't exist a preceding node equal to the reference node". Therefore, keeping the first and rejecting the last is the correct behaviour.

How to signify before and after with an if else statement

I want to tell python that everything before a certain character in a string, equals something else. In this code, I want everything after the equals sign to be assigned to a separate list called results, and everything before the equals sign to be assigned to a whole other list called names.
I believe an if/else statement is needed, but I do not know how to signify BEFORE and AFTER in python.
lines = ['Data1 = 100',
'Data2 = TRUE',
'Data3 = 45',
'Data4 = False',
]
You could make use of the list() function. Which splits the string into characters. Your problem with this is that you'll have to either specify the position on number of time the character appears before hand in order to get a start and stop location.
Another option is using the str.replace() if you know exactly what you want to replace, but both of these method present the problem that they are hard coded. If you're only wanting to replace them within a conditional statement, these could be useful.
For your use, you could say something like
loop through array.
split the element in the array using split
add logic statement that if array[i-1] == "=", start replacing elements with new element
then add the new element back into the array at the position you removed wanted to be removed.

Filtering on inner table in nested tables

sometimes I have a nested table (table in a table cell) and would like to apply a filter on the inner table using Schematiq functions.
The general function call is clear to me, but the issue occurs when it comes to applying the right quotes to the various arguments.
I would like to filter on a specific string, but as I am already using double quotes for the outer function snippet and single quotes for the inner function snippet, I don't know what to use to quote the string I am filtering for.
I have tried several options, the last one is
=tbl.CalculateColumn(C23,"Result","r =>tbl.Filter(r,'tier_info2','=SPOT2')")
Can you please help how to solve this?
You're actually very close to the right solution here, in that tbl.CalculateColumn() allows you to do whatever you like to the values in a column, so in this case applying a table function like tbl.Filter() to a column of tables is exactly the right thing to do. The difficulty is actually in getting the nested quotes right in the snippet.
Schematiq allows you to use either single or double quotes in snippets, which you're doing, however the inner snippet you're passing to 'tbl.Filter()' needs to have quotes around SPOT2 otherwise (in an Excel formula) SPOT2 is treated as a named range rather than as text. To write a literal quote within a quote, you have to double it, so the following ought to work for you:
=tbl.CalculateColumn(C23,"Result","r =>tbl.Filter(r,'tier_info2','=''SPOT2''')")
(note that I've added two single quotes either side of SPOT2)
All this nesting of quotes is a bit awkward though, so one alternative is to move the snippet to its own cell. This also probably makes your sheet a bit easier to read:
C24: r => tbl.Filter(r, "tier_info2", "='SPOT2'")
C25: =tbl.CalculateColumn(C23, "Result", C24)
By moving the snippet into its own cell, there's no need to wrap the whole thing in double quotes, so you can use double quotes around the snippet and single quotes around the text value.
Another alternative is to make the inner filter snippet into an input to the function, and use fn.FixInput() to provide its value to the calculation:
C24: (fn, tbl) => tbl.Filter(tbl, 'tier_info2', fn)
C25: '='SPOT2'
C26: =tbl.CalculateColumn(C23, "Result", fn.FixInput(C24, C25))
fn.FixInput() fixes the fn input to the snippet in C24 to always be the snippet from C25, then tbl.CalculateColumn() applies the function by passing the column values as the remaining tbl input. By separating the two snippets, it makes it easier to see and later amend the filter logic if you need. Of course, this approach could also be combined back into one cell, and this is what I would recommend overall if you want to keep your formula in just one cell:
=tbl.CalculateColumn(C23,"Result", fn.FixInput("(fn, tbl) => tbl.Filter(tbl, 'tier_info2', fn)", "='SPOT2'"))

how to find the characters between 2 strings in excel

I have an xml file imported into excel with the tags. How do i retrieve the value of the string between 2 strings.
Eg. "<"product_offer_group_id">"686819743"<"/product_offer_group_id">"
How do i retrieve 686819743 from this. To note the string length is varying and ranges from 1 to 20 digits.
you need to procced in excel? Not sure about possibility of usage of regular expressions(which are a pretty good solution for that case) in Excel standard functions, but with VBA You can for sure.
look here:
http://lispy.wordpress.com/2008/10/17/using-regex-functions-in-excel/
Alternativelly you can also try to play with standard Excel Text functions, like find, left, right etc.
If you want a solution without using VB script and only Excel functions, assuming your value is in cell A1, the following use of MID, FIND, and CHAR functions would work:
=MID(A1,FIND(CHAR(34)&">"&CHAR(34),A1,1)+3,FIND(CHAR(34)&"<"&CHAR(34),A1,FIND(CHAR(34)&">"&CHAR(34),A1,1)+1)-FIND(CHAR(34)&">"&CHAR(34),A1,1)-3)
The above searches for the first occurrence of the tag ">", and takes whatever is between that tag and the next occurring "<" tag.
The magic number 3 in the function is the length of these two searched tags and used to cut down on calling an additional LEN(CHAR(34)&">"&CHAR(34)) function.

Resources