Clicking a "add comment" button - record

When I am recording my script my scrpit is failing when it is coming to the part of clicking the "add comment" icon. The error I am getting is that the element is not found. The html script is :
a id="cmt_place" class="btn add_comment" onclick="javascript:SNI.Community.Toolbox.TopNavCheckandShow()">
So I am confused which command I should use and what the target and value should be so that when the test runs it should be able to automatically click the add comment icon.
New Test Case
open /registration/login.esi
type id=up-ur-email
type id=up-ur-password
click css=#up-ur-widget-login > #up-ur-widget-nav-item-off > a > em
open /home/home.esi
click link=TEST_upload
click id=Add Comment
click id=commenttext
type id=commenttext test123
click css=#post-comment-omnt > em
clickAndWait link=Log Out

open /registration/login.esi
type id=up-ur-email
type id=up-ur-password
click css=#up-ur-widget-login > #up-ur-widget-nav-item-off > a > em
open /home/home.esi
click link=TEST_upload
Pause 30000
click id=Add Comment
click id=commenttext
type id=commenttext test123
click css=#post-comment-omnt > em
clickAndWait link=Log Out
pause command will pause 3 second before click the Add comment button.
Try this.
Thank you.

use Xpath of comment box in target field and use pause & setCursorPosition command
pause to wait for some time and setCursorPosition command to point comment box
open /registration/login.esi
type id=up-ur-email
type id=up-ur-password
click css=#up-ur-widget-login > #up-ur-widget-nav-item-off > a > em
open /home/home.esi
click link=TEST_upload
click id=Add Comment(use Xpath of comment box instead of this)
pause 2000
setCursorPosition id=commenttext
click id=commenttext
type id=commenttext test123
click css=#post-comment-omnt > em
clickAndWait link=Log Out

Related

Access to a pop-up in selenium

I do have the following code to click a Google button that open a pop-up and then it selects the second Item. It worked fine but now is failing, I guess that due to ID name changed. I do not remember how I Inpectioned the pop-up ID since it does not appears in the "Inpection" Chrome Window.
numOpiniones.click()
self.driver.find_element(By.XPATH,"//button[#data-value='Ordenar']").click()
sleep(random.uniform(1, 1.5))
self.driver.find_element(By.XPATH, "//li[#role='menuitemradio' and #data-index='1']").click()
"menuitemradio" does not exists anymore but I can not see that element in the inspector panel when is created/displayed.
enter image description here
You can use the following css path
driver.find_element(By.CSS_SELECTOR, '#hovercard > #action-menu > [data-index="1"]')

Copy from Excel to Browser

How do I "paste" in Selenium/VBA to browser textfield?
I downloaded and installed this: https://code.google.com/p/selenium-vba/
I managed to start Selenium in Firefox (CTRL-ALT-S) and recorded my steps for automation. I changed the code language to VBA in there and copied it to paste it in Excel.
For those of you who want to know what to do in Excel (2013):
Right click "Start"
Customize Ribbon
Check "Developer Tools" on the right
Click OK > Click on "Developer Tools" > Click "Visual Basic" > Click "Extras" > Click "References" > Look for "SeleniumWrapper Type Library" and check it > Click OK > In Menu bar click on the top arrow beside "Paste UserForm" > Click "Module" > Now paste the VBA Code from Selenium (Firefox) Plugin in there
Everything works perfectly fine but I want it to do repetitive web browser tasks so it should copy Excel cells and paste it in Textboxes in Websites for example in the Google Searchbar.
I already found a solution for the copying part:
Range("A1").Copy
It works but I can't find any working solution for the pasting part. Tested but didn't work:
driver.findElementById("ID").SendKeys "^v" gives out "v" instead of pasting.
driver.findElementById("ID").SendKeys(Keys.chord(Keys.CONTROL, "v")); Doesn't accept ";" and also doesn't work without.
I also tried several "Wait" and "Sleep" codes but neither do I know for sure which of them actually work nor if they are necessary.
driver.action.key_down(: control) Didn't work.
driver.findElementById("ID").keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0076')).perform(); Syntax error, without ";" "Error: List Delimiter" and marks the "." between "String" and "value".
I am grateful for any advice!
The easiest way is to send the text:
Dim driver As New FirefoxDriver
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
driver.FindElementById("searchInput").SendKeys [A1]
If you really need to use the clipboard:
Dim Keys As New Selenium.Keys
Dim driver As New Selenium.FirefoxDriver
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
driver.SetClipBoard [A1]
driver.FindElementById("searchInput").SendKeys Keys.Control, "v"
Of course it depends on the kind of element you want to paste the text to, but how about just setting the element's value directly;
driver.findElementById("ID").text = Range("A1").value2

Selenium select a text in a not select input

How to select an element in this web element :
this input is a text type and not a select option !!!
Type some characters (or all/none of them) in that input box
Wait until the options appear
Take the identifier (id/XPath/class/CSS/etc.) of that element (option) (maybe it is a div)
F12 in Chrome > click on the magnifier > click on the option
F12 in Firefox/Internet Explorer > click on the arrow > click on the option
Click on that elements / take its content

Selenium IDE: how to popup a dialog and wait for user to click OK

Just wonder if we could do something like below when running a selenium scenario, which needs user's interaction to continue. Like wait for him to upload some images..
Till the step, the selenium popup a dialog saying: please complete something, then click the OK button to continue.
When user finishing the operation on the webpage, then click "OK", then the scenario's transaction is moving forward. Otherwise, stop on that step.
For the first bullet, I was thinking of below command:
Command:
waitForConfirmation
Target:
javascript{confirm("Please upload the images, then click OK to continue")}
Thanks in advance!
In selenium ide use storeeval command, different type of boxes
COMMAND | TARGET | VALUE
----------------------------------------------------------------------------
storeeval | alert("This is alert box") |
storeeval | prompt("This is prompt box. Please enter the value") | text
storeeval | confirm("this is cofirm box") |
Type | locator of text box | ${text}
1.) we can create a message box and can assign the value given in the message box to a text box.
Command:StoreEval
Target:prompt{("Enter the Message")}
Value:Text
here a pop up message box will pop up and you can enter some text into it and it will store in the variable "Text" the value in the Text can be assigned to a text box or other
Command:type
Target:id=id of the text box
value:${Text}
2.)same as above we can create an alert box
Command:StoreEval
Target:alert{("Enter the Message")}
Try these things
Thank you.

Code reformatting on save in PhpStorm or other jetbrains ide

How can I set up that the code is reformatted automatically on saving?
So I don't always have to press Ctrl + Alt +
L.
Actually it is possible.
The idea is to record a very simple macro that selects all the lines (Ctrl+A), formats (Ctrl+Alt+L), deselect all (Up and Down arrow) and saves a file (Ctrl+S), and bind this macro to Ctrl+S.
Free Ctrl+S changing keyboard shortcut for "Save all"
open File > Settings;
search for "keymap" and open it;
search "Save All" and double click the action "Save all";
select "Remove Ctrl+S";
double click "Save All" again and select "Add Keyboard Shortcut";
select "Ctrl+Alt+Shift+S" as first stroke.
Confirm and exit from Settings.
Record the macro
Edit > Macros > Start Macro recording
Press Ctrl+A, then Ctrl+Alt+L, then Up arrow, then Down arrow, and finally then Ctrl+Alt+Shift+S
Stop recording the macro clicking on the Stop button on the bottom right of the page.
Give this macro a name like "Format and Save"
Assign Ctrl+S to "Format and Save"
open File > Settings;
search for "keymap" and open it;
search "Format and Save" and double click the action "Format and Save";
select "Add Keyboard Shortcut";
select "Ctrl+S" as first stroke.
Confirm and exit from Settings.
Finally, enjoy PhpStorm!
I use Save Actions Plugin https://plugins.jetbrains.com/plugin/7642-save-actions for PhpSorm
Settings -> Tools -> Action on Save -> Reformat code
Another thing that I found very helpful in combination with this macro is the
Show Reformat File Dialog.
In case you want to only reformat the code you just changed, you can set the option:
Only VCS changed text
The dialog can be opened through the following shortcut:
CTRL+ALT+SHIFT+L
Checked on PHPStorm 2020 & greater versions and found a plugin named Save Action. But make sure you configure for new and exisiting projects.
You can also export your PHPStorm settings and then unzip & replace/create the following :-
Macro File under Settings/Option/macro.xml
<application>
<component name="ActionMacroManager">
<macro name="Format & Save">
<action id="ReformatCode"/>
<action id="SaveAll"/>
</macro>
</component>
</application>
Settings/Keymaps/Default Copy.xml
<keymap version="1" name="Default copy" parent="Default for XWin">
<action id="DBNavigator.Actions.SourceEditor.Save"/>
<action id="Macro.Format & Save">
<keyboard-shortcut first-keystroke="ctrl s"/>
</action>
<action id="SaveAll">
<keyboard-shortcut first-keystroke="shift ctrl alt s"/>
</action>
</keymap>
Now Zip it back & import it & whenever you press ctrl+s - Auto Code Format will be done.
From v2017.2.4 CTRL + ALT + L doesn't work. Use alt + F8 instead.
Solution:
Use: ALT + F8 to format the code.
When creating a macro as described by Luca Mastrostefano, use:
alt + F8 to format and then ctrl + alt + s to save.