How to select dropdown if it is not have id and label in selenium - selenium

Here is my HTML
<option ng-selected="user.id == userDetail.assignedTo.id" ng-repeat="user in assignableUsers | orderBy:user.name" value="9,5304" class="ng-binding ng-scope">
User1
</option>
<option ng-selected="user.id == userDetail.assignedTo.id" ng-repeat="user in assignableUsers | orderBy:user.name" value="19,5304" class="ng-binding ng-scope">
User2
</option>
It has list of dropdown values. I wanted to select say eg., User2.
If I give select by Label is not working since it does not have label and
value also it has id not text (which is dynamic number build to build).
Only option is selectByIndex by 2. If incase, User11 exists then it takes User11 as the dropdown list orders by alpahbetically ascending..
I have option to take getText for Each Index and match it User2 then select that index.. Is that only way or any other solution?

Related

How to use tokens from 2 time range inputs in single Splunk dashboard query?

I'm using Splunk classic dashboards where I have 2 time range inputs. I want to compare data for 2 time frames in a single table. Essentially, I want to perform query which counts errors by type for period A and B, then join the searches by error type so that I can see how many errors of each type there were in period A as opposed to period B.
I added a panel as follows:
because I want to use tokens from both time inputs for the query:
(index=myindex) earliest="$runATimeInput.earliest$" latest="$runATimeInput.latest$" environment="$runAEnvironment$" level=ERROR
| spath input=message
| stats count by logIdentifier
| sort count desc
| join left=L right=R where L.logIdentifier = R.logIdentifier
[| search (index=myindex) earliest="$runBTimeInput.earliest$" latest="$runBTimeInput.latest$" environment="$runBEnvironment$" level=ERROR
| spath input=message
| stats count by logIdentifier ]
The problem is that the query doesn't return any results although it should. The main query returns results:
(index=myindex) earliest="$runATimeInput.earliest$" latest="$runATimeInput.latest$" environment="$runAEnvironment$" level=ERROR
| spath input=message
| stats count by logIdentifier
| sort count desc
However the subsearch query doesn't return any results (although a separate search for the same period in a new tab returns results):
[| search (index=myindex) earliest="$runBTimeInput.earliest$" latest="$runBTimeInput.latest$" environment="$runBEnvironment$" level=ERROR
| spath input=message
| stats count by logIdentifier ]
When I click on Run Search in Splunk panel in order to open the search in a new tab I see strange values for earliest/latest tokens. For the main query the values are: earliest="1669500000" latest="1669506493.677" where 1669500000 is the Tue Jan 20 1970 09:45:00 and 1669506493.677 is Sun Nov 27 2022 01:48:13 whereas the timeframe for period 1 was Sun Nov 27 2022 00:00:00 - Sun Nov 27 2022 01:48:13. That being said the main query works and it respects the original time frame.
The values for the second query are earliest="1669813200" latest="1669816444.909" where 1669813200 is Tue Jan 20 1970 09:45:00 and 1669816444.909 is Wed Nov 30 2022 15:54:04 whereas the period 2 timeframe was Wed Nov 30 2022 15:00:04 - Wed Nov 30 2022 15:54:04`.
Am I doing something wrong in the panel settings or the query? Or maybe there's another way to do this in Splunk?
Below is the dashboard XML:
<form>
<label>My Dashboard</label>
<description>My Dashboard</description>
<fieldset submitButton="false" autoRun="true">
<input type="time" token="runATimeInput" searchWhenChanged="true">
<label>Run A</label>
<default>
<earliest>-24h#h</earliest>
<latest>now</latest>
</default>
</input>
<input type="dropdown" token="runAEnvironment" searchWhenChanged="true">
<label>Run A Environment</label>
<choice value="prod">prod</choice>
<default>prod</default>
</input>
<input type="time" token="runBTimeInput" searchWhenChanged="true">
<label>Run B</label>
<default>
<earliest>-24h#h</earliest>
<latest>now</latest>
</default>
</input>
<input type="dropdown" token="runBEnvironment" searchWhenChanged="true">
<label>Run B Environment</label>
<choice value="prod">prod</choice>
<default>prod</default>
</input>
</fieldset>
<row>
<panel>
<title>Top Exceptions</title>
<table>
<title>Top Exceptions</title>
<search>
<query>(index=distapps) earliest="$runATimeInput.earliest$" latest="$runATimeInput.latest$" environment="$runAEnvironment$" level=ERROR | spath input=message
| stats count by logIdentifier
| sort count desc
| join left=L right=R where L.logIdentifier = R.logIdentifier
[| search (index=myindex) earliest="$runBTimeInput.earliest$" latest="$runBTimeInput.latest$" environment="$runBEnvironment$" level=ERROR
| spath input=message
| stats count by logIdentifier ]</query>
<earliest>$runATimeInput.earliest$</earliest>
<latest>$runBTimeInput.latest$</latest>
</search>
<option name="drilldown">none</option>
<option name="refresh.display">progressbar</option>
</table>
</panel>
</row>
</form>
Here's a test dashboard I created that uses two timepickers. It produces results for both time periods. How is yours different? Could it be the count field is used in both the main and subsearches?
<form version="1.1">
<label>test</label>
<fieldset submitButton="false">
<input type="time" token="runATimeInput">
<label>A</label>
<default>
<earliest>-24h#h</earliest>
<latest>now</latest>
</default>
</input>
<input type="time" token="runBTimeInput">
<label>B</label>
<default>
<earliest>-48h#h</earliest>
<latest>-24h#h</latest>
</default>
</input>
</fieldset>
<row>
<panel>
<table>
<search>
<query>(index=_internal) earliest="$runATimeInput.earliest$" latest="$runATimeInput.latest$"
| stats count as countA by component
| join component [| search (index=_internal) earliest="$runBTimeInput.earliest$" latest="$runBTimeInput.latest$"
| stats count as countB by component ]</query>
<earliest>$runATimeInput.earliest$</earliest>
<latest>$runATimeInput.latest$</latest>
<sampleRatio>1</sampleRatio>
</search>
<option name="drilldown">none</option>
<option name="refresh.display">progressbar</option>
</table>
</panel>
</row>
</form>
Don't use any tokens or time selector on the panel itself
You should be able to reference your two time tokens' .earliest and .latest just fine in any searches on the dashboard

JINJA (dbt) Is it possible to make a new table with several rows based on items within a single column separated by a symbol?

I have a table with the following data structure:
ID
Tag
1
blue,red,green
2
white,blue
I would like to convert this to a new table with the following structure:
ID
Tag
1
blue
1
red
1
green
2
white
2
blue
Is this possible to do within dbt, using JINJA (or some other method)? My DWH is fully hosted within Google BigQuery and connected to dbt.
Please see Mikhail's comment for the simple, directly BQ way of doing this operation if that's all you need.
However, a more dbt generalized (jinja-sql) version of doing this such as when you know in advance you will eventually have to migrate a project from one SQL syntax to another (I had to do PL/pgSQL to Bigquery's Standard-SQL) could use database agnostic functions from the dbt-utils package like:
split_part
pivot / unpivot
get_column_values
A code sample which uses these functions could look something like:
split.sql
with source as (
select ID,Tag from {{ ref('idtag') }}
), split as (
select
s."ID",
{{ dbt_utils.split_part( s."Tag" , "','", '1') }} as Tag_1,
{{ dbt_utils.split_part( s."Tag" , "','", '2') }} as Tag_2,
{{ dbt_utils.split_part( s."Tag" , "','", '3') }} as Tag_3
from source s
)
select ID, Tag_1, Tag_2, Tag_3 from split
unpivot.sql
with unpivot as (
{{ dbt_utils.unpivot(ref('split'), cast_to='varchar', exclude=['ID']) }}
)
select "ID", "value" as split_tags
from unpivot
where "value" is not null
group by 1,2
Which for some reason, the split_part isn't working correctly on my local dbt installation right now but I hope you find some value in the intent.

Moving SQL record up or down Based on the number inserted or removed

I have a select list of records that have a number 1-10.
The value for each <option> is the id from the record on the database and the text is another column value --- numToDo. (see below)
<select>
<option value="101">1</option>
<option value="102">2</option>
<option value="103">3</option>
<option value="104">4</option>
<option value="105">5</option>
...
</select>
I want to allow the user to add/remove and readjust items from the list, but I want the list to remain in order if 1-10. In other words if the person thinks record 105 should be completed before 102 I would like the current 2-(102) to be moved down and have the rest of those records 104,105 etc to change as well.
in other words have it look like this:
<select>
<option value="101">1</option>
<option value="105">2</option>
<option value="102">3</option>
<option value="103">4</option>
<option value="104">5</option>
....
There are only ever 10 items or less listed at a time, and when they get completed the numToDo for the record becomes a 0 which gets moved out of the list and the numbers should be moved up as well, but if I can just get help with the first part I mentioned I can figure the rest out on my own.
I'm assuming this would be a query on the database end where it takes in the ID and the new number and updates the current row and then updates the rest based on the number affected? I don't really work on SQL so i'm not really sure if this can be done.
Use a record you can sort on, and when you move a record to a new spot, just ensure that the record sorting places it at the right spot. If you eg have this ordering
Sorting
Record# order
101 1
102 2
103 3
104 4
105 5
you can move record 105 to the second spot by only updating one sorting key like this.
Sorting
Record# order
101 1
105 1.5 < average of record 101 and 102's Sorting key
102 2
103 3
104 4

Ruby on Rails: Left Outer Join with Sort

I have a RoR application for sending emails, I have the models Contacts, Recipients, and Users, whereby a user can have many contacts and a contact can have many recipients. The data looks like this:
User
ID Name
1 Ben
2 Emily
3 Brian
Contact
ID Name User_ID
1 Jack 1
2 Joe 2
3 Chloe 2
4 Jacob 1
5 Trevor 3
Recipient
ID Contact_ID Email_ID (not relevant for this question)
1 1 2
2 1 1
3 4 5
4 1 6
5 2 8
What I want to do is on the index page for contacts, display all the contacts belonging to a user allow the user to choose what to order them by, such as name and the amount of emails received.
The problem I have is that I can display all the contacts belonging to a user no problem, but I am struggling to allow a user to sort the contacts by the amount of emails they have received. The amount of emails they have received can be calculated by counting the amount of recipients with the same contact id. The reason I have this problem is because I want to display all the contacts belonging to a user irrespective of whether they have received emails (a contact may have received 0 emails). The code I have tried is:
#contacts = Contact.where(user_id: session[:user_id]).all.order(params.fetch(:sort, 'id asc'))
But this doesn't allow a user to sort by the amount of emails the contacts have received.
I have also tried this:
#contacts = Contact.where(user_id: session[:user_id]).joins(:recipients).group('contacts.id').all.order(params.fetch(:sort, 'id asc'))
But this only displays the contacts who have received emails.
And I have also tried this:
#contacts = Contact.where(user_id: session[:user_id]).joins("LEFT OUTER JOIN contacts ON contacts.id = recipients.contact_id").all.order('max(recipients.contact_id) DESC')
This displays all contacts who have and have not received emails and allows sorting, but it shows duplicate data. I.e. using the above data, if Ben were to look at his contacts (user_id 1) he could see Jack and Jacob, but because Jack has received 3 emails he would see the following:
First Name:
Jack
Jacob
Jack
Jack
Jack
Is there a way to solve this? Please note that I am currently using the following code on index.html.erb to allow a user to select what they want to order the records by:
<form>
Order By:
<select name="sort">
<option value="firstname ASC">First Name (A - Z)</option>
<option value="firstname DESC">First Name (Z - A)</option>
<option value="surname ASC">Surname (A - Z)</option>
<option value="surname DESC">Surname (Z - A)</option>
<option value="email ASC">Email (A - Z)</option>
<option value="email DESC">Email (Z - A)</option>
<option value="max(recipients.contact_id) ASC">Emails Recieved (Low - High)</option>
<option value="max(recipients.contact_id) DESC">Emails Recieved (High - Low)</option>
<option value="updated_at ASC">Date Updated (Oldest First)</option>
<option value="updated_at DESC">Date Updated (Newest First)</option>
</select>
<button>
Go
</button>
</form>
In order to do a LEFT OUTER JOIN try this:
Contact.includes(:recipients).references(:recipients)
Note: This will also preload recipients and add a ton of SQL to the query
If you also want to do the sorting, then you should be able to do so like this:
Contact.includes(:recipients).references(:recipients).group("contacts.id, recipients.id").order("COUNT(recipients.id) ASC")
try this.
#contacts = Contact.select('contacts.*, count(recipients.id) as emails_received')
.where(user_id: session[:user_id])
.joins(:recipients)
.group('contacts.id')
.order('emails_received ASC')
If you want to show the ones that didn't receive email, you need left outer join.
#contacts = Contact.select('contacts.*, count(recipients.id) as emails_received')
.where(user_id: session[:user_id])
.joins('LEFT OUTER JOIN recipients ON recipients.contact_id = contacts.id)
.group('contacts.id')
.order('emails_received ASC')

Choosing and keeping multiple radio button value inside a table

I am using radio button for choosing employee type such as part-time , full-time etc.I could choose only one item according followed table structure.How can i select multiple radio button and keep these inside a table.For instance such as keeping inside an array?
+--------------+----------------+
| EmployeeId | EmployeeType |
+--------------+----------------+
| 2 | 2 |
+--------------+----------------+
| 3 | 1 |
+--------------+----------------+
EmployeeTypes :
0 Part-time
1 Full-time
2 Consultant
3 Trainer
In HTML, radio buttons work by posting different values to the same name - the value of the item selected.
<form action="">
<input type="radio" name="sex" value="male">Male
<input type="radio" name="sex" value="female">Female
</form>
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio
However, if you have a table of data, and you need to be able to edit multiple rows at the same time, there will be the need to differentiate between EmployeeType for User 2 and EmployeeType for User 3. So the radio buttons with various values might now instead post to names such as EmployeeType_2 and EmployeeType_3.
This is essentially what will happen behind the scenes when you try to do code like the following.
How can I post a list of items in MVC
At some point here you may want to actually consider using a grid control, but I'm not trying to plug Telerik or DevExpress controls. So, instead I'll mention the following that came up in my search. Perhaps other users can suggest other controls.
http://www.codeproject.com/Tips/720348/MVC-Grid-Inline-Edit
http://www.codeproject.com/Articles/165410/ASP-NET-MVC-Editable-DataTable-jQuery-DataTables-a