Can't select nth element of same class with xpath / selenium IDE - selenium

Don't understand why the following loop doesn't work except for nth element with same class fails on the 2nd element (I'm presuming 1st element works because it's also the root in xpath):
{
"Command": "storeEval",
"Target": "$('.className').length",
"Value": "max"
},
{
"Command": "store",
"Target": "1",
"Value": "i"
},
{
"Command": "while",
"Target": "(${i} < ${max})",
"Value": ""
},
{
"Command": "echo",
"Target": "Current value of i = ${i}",
"Value": "i"
},
{
"Command": "storeAttribute",
"Target": "//a[contains(#class, 'className')][${i}]#href",
"Value": "link"
},
{
"Command": "endWhile",
"Target": "",
"Value": ""
}
For debugging, I tried to change ...[${i}] to [2] and it fails with both Kantu & Ranorex Selocity. However, From my reading of xpath / Selenium IDE documentation, this syntax should be correct. Any advice?
PS. For reference, the .className is actually .rf-project-cover__title on the page https://www.behance.net/search?field=132&content=projects&sort=published_date&time=week

I think you want to search, then extract i-th item, so you need brackets:
(//a[contains(#class, 'className')])[${i}]
for example:
(//a[contains(#class, 'rf-project-cover__title')])[2]
returns item with link text my portfolio

Related

Microsoft adaptive card choiceset iteration

i have a adaptive card choice set like below, as you can see am trying to get the value under title from a variable which is an array, is there a way i can iterate the choice set automatically because i don't know how many values the array has i want to show all the values inside the array in the choice set title
{
"type" : "Input.ChoiceSet",
"isMultiSelect": true,
"id": "myColor",
"style": "compact",
"value": "1",
"choices": [
{
"title": vars.responsedata.items[0].topic,
"value": "1"
},
{
"title": vars.responsedata.items[1].topic,
"value": "2"
},
{
"title": "Recording 3 sample",
"value": "3"
}
]
}
You can use the map() function.
Example in DataWeave:
{
choices: vars.responsedata.items map {
title: $.topic,
value: $$
}
}

automating deleting Yahoo emails

I am using Selenium IDE in Firefox to try to delete unread emails from Yahoo mail. We have around 30,000 unread emails and, from what I see, Yahoo will only delete less than 100 each time you delete.
I recorded the steps. When I play them back, the dropdown to select "unread" gets clicked. However, the "unread" doesn't get displayed to click on it.
Also, is there a way to "read" what is displayed on the screen? Sometimes Yahoo asks to confirm the deletion, sometimes it doesn't. Is there a way to conditionally click it if it is there?
The odd thing is that the deleting worked for a while today and then reverted to the "unread" not getting displayed. I find that hard to understand.
Thanks
It's June 2021 and I have a solution:
Took me 10 min to recover 5 years old knowledge. Done via Selenium IDE, easy to install in FFox. then run script/project which I attached.
It's set now to run first delete with Prompt confirmation and then 40 times in the loop without. This is how it works in my security setup and I'm in US, CA.
I imagine that for diff areas or security you might need that confirmation each time on css=.M_1MYwXA:nth-child(3) .D_F Are you Sure button
I overall don't like this Se, dealt with it around 5 years ago, now they change interface and editing capababilites, if any Se guru here he/she can easely make it run smoother I think.
Prerequsites:
Before login into your yahoo in FFox and make it remember your password so script will login automatically, there is no any private data in it or stored passwords. This script will delete mail from default Folder = Inbox, make sure that upon login you're there.
Store code below as ddd.side (extension for IDE)
Then you can watch 3min demo how to install IDE, open and run project.
All steps setup to run with to handle delays, but still it's not a bulletproof, in my case I had to restart FF couple of times. Sometime it just doesn't open base url on first step.
I kept it running for couple of hours and it's DONE. 54000 emails of my wife gone.
I don't think I can attachd this file, so trying to paste,
LEt me know. This script works fine as of June 30 2021, yahoo guys don't sleep so it might be different overtime.
{
"id": "adc727d1-40c6-439d-8702-8f97739c8f44",
"version": "2.0",
"name": "X",
"url": "https://mail.yahoo.com/",
"tests": [{
"id": "ffe439e1-39aa-4114-95f9-14b5cee731dd",
"name": "X",
"commands": [{
"id": "5f61ee21-9745-485e-b113-d1515783dc68",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "5d019986-41d9-451a-a328-2681a6d3f439",
"comment": "",
"command": "times",
"target": "40",
"targets": [],
"value": ""
}, {
"id": "89048b9d-1e3c-4e56-b8c7-17a9fe431233",
"comment": "",
"command": "click",
"target": "css=.G_e > .D_F .D_F",
"targets": [
["css=.G_e > .D_F .D_F", "css:finder"],
["xpath=//div[#id='mail-app-component']/div/div/div/div/div/div/div/ul/li/span/button/span", "xpath:idRelative"],
["xpath=//span/button/span", "xpath:position"]
],
"value": ""
}, {
"id": "2a5a4320-d12e-43ef-8f13-ea340c3062a3",
"comment": "",
"command": "pause",
"target": "3000",
"targets": [],
"value": ""
}, {
"id": "af49e7c3-6db0-4236-aa1f-93d94f2acf5c",
"comment": "",
"command": "click",
"target": "css=.M_1MYwXA:nth-child(3) .D_F",
"targets": [
["css=.M_1MYwXA:nth-child(3) .D_F", "css:finder"],
["xpath=//div[#id='mail-app-component']/div/div/div/div/div[2]/div/div[3]/button/span", "xpath:idRelative"],
["xpath=//div[3]/button/span", "xpath:position"],
["xpath=//span[contains(.,'Delete')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "5c463aa8-4782-473e-876c-73921aa75612",
"comment": "",
"command": "pause",
"target": "1000",
"targets": [],
"value": ""
}, {
"id": "b089bb86-60f4-43ee-8031-e5ac930f2f71",
"comment": "",
"command": "click",
"target": "css=.G_e > .D_F .D_F",
"targets": [],
"value": ""
}, {
"id": "3731ebc1-a0c9-46ac-8d7d-c56a2cf3b72a",
"comment": "",
"command": "click",
"target": "css=.M_1MYwXA:nth-child(3) .D_F",
"targets": [
["css=.M_6LEV", "css:finder"],
["xpath=(//button[#type='button'])[192]", "xpath:attributes"],
["xpath=//div[#id='modal-outer']/div/div/div/div[4]/button", "xpath:idRelative"],
["xpath=//div[7]/div/div/div/div/div[4]/button", "xpath:position"],
["xpath=//button[contains(.,'OK')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "cbb516e3-5c38-4ebe-b6ff-65f0fde58cb6",
"comment": "",
"command": "click",
"target": "css=.M_6LEV",
"targets": [],
"value": ""
}, {
"id": "a5a50691-fe3f-4e2f-8788-cad5f9ef18fc",
"comment": "",
"command": "end",
"target": "",
"targets": [],
"value": ""
}]
}],
"suites": [{
"id": "2f69f4d6-3aad-4a60-a137-15541cf6384a",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["ffe439e1-39aa-4114-95f9-14b5cee731dd"]
}],
"urls": ["https://mail.yahoo.com/"],
"plugins": []
}

Multiple actions on one keyboard shortcut in vscode

Is it possible to have multiple actions assigned to one keyboard shortcut in visual studio code?
For example:
Move cursor up x 3 set to "ctrl + w"
Thanks in advance.
It's possible with extensions like Commands [Note: Created by the post's author]
settings.json
"commands.commands": {
"down3": {
"sequence": [
"cursorDown",
"cursorDown",
"cursorDown",
],
},
},
keybindings.json
{
"key": "ctrl+w",
"command": "down3",
},
Or with just keybindings.json
{
"key": "ctrl+w",
"command": "commands.run",
"args": [
"cursorDown",
"cursorDown",
"cursorDown"
]
},
Feature request to support Macro like keybindings #871.
Although, for this particular example it's better to use the built-in command (to avoid any jumpiness):
{
"key": "ctrl+w",
"command": "cursorMove",
"args": {
"to": "down",
"by": "line",
"value": 3
}
}
https://code.visualstudio.com/api/references/commands
I use the macros extension:
in settings.json:
"macros": {
"showGit": ["workbench.view.scm", "git-graph.view"]
}
then in keybindings.json:
{
"key": "ctrl+shift+g",
"command": "showGit"
}

I want tab to insert a tab in Sublime Text but it activates the autocomplete

I am using Sublime CodeIntel which I like for the autocomplete, however it pops up and inserts words while I am trying to insert tabs. I want tab to always insert a tab unless the character before my cursor is a letter.
I reckon this could be done with a user keymap for the tab key to look at context, but I don't know how to do it.
Something like the following should work. You may need to play with the order of the key bindings. Add the following to your user key bindings
{
"keys": ["tab"], "command": "insert", "args": {"characters": "\t" }, "context": [
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[^a-zA-Z]$", "match_all": true }
]
}
Note that I don't have SublimeCodeIntel installed, so unsure how it will behave with that.
As a nice debugging tip, enter sublime.log_commands(True) into the ST console to see what command is being executed for a particular key binding. May be useful in confirming that the command is running as you expect.
A quick work around would be using Autohotkey if you are on windows.
you can assign any keys to 4 spaces like below
`::
Send {Space 4} ; when pressed ` enters four times Space bar
Return
Try this... Overrides tab key to function as indent key and insert tab char only
Preferences > Key Bindings
[
{ "keys": ["tab"], "command": "insert", "args": {"characters": "\t"} },
{ "keys": ["tab"], "command": "reindent", "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
]
},
{ "keys": ["tab"], "command": "indent", "context":
[
{ "key": "text", "operator": "regex_contains", "operand": "\n" }
]
},
{ "keys": ["tab"], "command": "next_field", "context":
[
{ "key": "has_next_field", "operator": "equal", "operand": true }
]
}
]

Add shortcut key for multiple plugins in Sublime Text 3

I'm using CodeFormatter and SassBeautify plugins in Sublime Text 3 in order to provide syntax highlighting and formatting for .scss files as well as .js/.html files. I've been able to set up shortcut keys for either plugin, but not to work for both, depending on the type of file I'm in.
[{
"keys": ["ctrl+alt+f"],
"command": "sass_beautify"
}, {
"keys": ["ctrl+alt+f"],
"command": "code_formatter"
}]
Can someone suggest how do to it? I've tried to understand "contexts" but not well enough to do this.
Am I doing this all wrong? Is there another way I should be achieving this?
Corrected keymap file:
[{
"keys": ["ctrl+alt+f"],
"command": "sass_beautify",
"context": [{
"key": "selector",
"operator": "equal",
"operand": "source.scss"
}]
}, {
"keys": ["ctrl+alt+f"],
"command": "code_formatter",
"context": [{
"key": "selector",
"operator": "not_equal",
"operand": "source.scss"
}]
}]
Add something similar to the following as a context entry
{ "key": "selector", "operator": "equal", "operand": "source.scss", "match_all": true }
{ "key": "selector", "operator": "equal", "operand": "(text.html, source.js)", "match_all": true }
The operand values are scope entries. There is a platform specific key binding to display scopes in the status bar, but I don't recall what they are off the top of my head. I personally use https://github.com/facelessuser/ScopeHunter to inspect scopes.