How do I simulate 'Enter' Key button with Node .Js /Selenium? - node.js

This is the code snippet I am using but it doesn't click
function ClickEnter(){
driver.findElement(webdriver.By.id('select2-result-label-3')).click();
}

You can send the 'Enter' key to an element like so:
driver.findElement(By.id('select2-result-label-3')).sendKeys(driver.Key.ENTER);
Taken from answer: Node.JS selenium send key enter

Related

telegram bot login checking authorization not equal hash

I try to use telegram bot connect website, when I open the website, I get the query and hash when I validate throw node.js and not equal
const key = crypto.createHash('sha256').update(my_bot_token).digest()
const validateHash = crypto.createHmac('sha256', key).update('auth_date=1646xxx\nfirst_name=namexxx\nid=1231xxxx\nAusername=alexLxxx').digest('hex')
console.log(hash === validateHash) false
I don't know where I am going wrong I try to use the npm package telegram-checking-authorization, but the same error
You should add all field data you receive from the request callback but remove the hash field.
Ex:
`auth_date=1665991955
first_name=xxxxx
id=xxxxxx
last_name=xxxxx
photo_url=xxxxxxx
username=xxxxx`
I try and succeed.
It happened to me as well, I described it in My question. You might copy the response from this API: https://oauth.telegram.org/auth/get?bot_id=xxx sometimes the response works with the function, sometimes it doesn't, and honestly, I don't understand why. Try to print user to console and check if the two hashes match!
What I have done is as follow:
I changed my bot's domain to https://www.w3schools.com/ and go to w3school online editor https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_indexof for example, print user object to console (replace the javascript in the online editor with code bellow and then replace YOUR-BOT-NAME in the code with the name of your bot):
<script async src="https://telegram.org/js/telegram-widget.js?21" data-telegram-login="YOUR-BOT-NAME" data-size="large" data-onauth="onTelegramAuth(user)" data-request-access="write"></script>
<script type="text/javascript">
function onTelegramAuth(user) {
console.log(JSON.stringify(user, null, 2));
}
</script>
press f12, go to console tab and then login with widget. Check the data printed on the console with your function.

How to get text in dash using dialog box?

I want to ask name of plot by using dialog box in dash like promp function in javascript but when I use {html.Script("prompt('text');", type='text/javascript') I have nothing in return.
I don't want to use text input or text area.
Thank you for your help.
The Dash documentation says the following on html.Script:
CAUTION: is included for completeness, but you cannot execute JavaScript code by providing it to a element. Use a clientside callback for this purpose instead.
https://dash.plotly.com/dash-html-components/script
As the documentation says here one option would be to use a clientside callback instead.
Minimal example to show the idea:
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.Div(id="content"),
html.Button(id="button", children="Show name of plot prompt"),
]
)
app.clientside_callback(
"""
function(n_clicks) {
if (n_clicks) {
nameOfPlot = prompt('name of plot')
return nameOfPlot
}
return "Name of plot placeholder"
}
""",
Output("content", "children"),
Input("button", "n_clicks"),
)
The Button click is the input for this callback. If nothing is clicked I return a placeholder text which sets the children property of a div with id content.
If the button has been clicked we can call prompt and do something with it.
With this approach you need an input and an output for the callback to work. You could also put the Javascript code in a .js file in an assets in your root application directory. For more info on client side callbacks see the documentation here.
Another approach would be to have a .js file in your assets folder and to put your prompt code there. You'd probably also want to set up some event listeners to wait for the page to load and/or to listen for button click events or other events that you could use to trigger the prompt at the right moment.

Error when trying to send text to application with Pywinauto: AttributeError

I am using Pywinauto to automate some interaction steps with an application that opens during a browser login session.
Lets call the application program.exe. It is actually a Chrome Extension that opens and prompts for a password.
import pywinauto as pwa
from pywinauto import application
from pywinauto import keyboard
app = application.Application()
app = app.Connect(path=r"C:\path\program.exe")
win.Part.Click() #not completely sure why i do this
app['Insert password']['Edit'].send('password')
It seems that I am able to connect to the program, but when I try to send text to the program I get an error. When i run the above this error occurs:
AttributeError: Neither GUI element (wrapper) nor wrapper method 'send' were found (typo?)
If i replace this:
app['Insert password']['Edit'].send('password')
With this:
app['Insert password'].SendKeys.send('password')
I get this error:
MatchError: Could not find 'SendKeys' in 'dict_keys(['Insert password for MyName:Static', 'Static', 'Insert password for MyName:Edit', 'Edit', 'OK', 'OKButton', 'Button', 'Button0', 'Button1', 'Button2', 'Cancel', 'CancelButton', 'Insert password for MyName:Static0', 'Insert password for MyName:Static1', 'Insert password for MyName:Static2', 'Insert password for MyName:', 'Static0', 'Static1', 'Static2'])'
There is no method send for any of the controls. SendKeys is not a method, but a function inside module keyboard so the correct usage is keyboard.SendKeys('password').
But method .type_keys('password') puts the control into focus and then does the same as keyboard.SendKeys. You may need to use with_spaces=True if password contains spaces. Special symbols like % must be escaped so: {%}. This method is powerful because it supports hot key combinations with Alt, Shift, Ctrl etc. See the docs about keyboard module. Usage for your case:
app['Insert password']['Edit'].type_keys('password', with_spaces=True)
Method .set_edit_text('password') can be even more useful: it doesn't type keys char by char, but sends the whole raw text to the control (no support for special keys, just text). This method doesn't require the control to be in focus.

How to sendKeys wherever the cursor is in selenium nodejs

I have created a script to comment in facebook posts, I did clicked on comment box, and cursor do appears but unable to perform .sendKeys()
here's my code:
var commentBox = driver.findElement(By.xpath('//*[#id="addComment_'+this.postIdSlice+'"]/div/div[2]/div/div/div/div[1]/div'));
actions.mouseMove(commentBox).click().perform();
driver.sleep(2000);
actions.sendKeys("Hello").perform();
but when I execute it doesnt sends 'Hello' to comment box.
PS: that postIdSlice is id of the post, no issues there just want to push/send string in that commentbox.
Use the Xpath to click on the comment box, then you can use the ActionSequence to sequnce input and ENTER key.
let action = new webdriver.ActionSequence(driver);
action.sendKeys("comment");
action.sendKeys(Keys.ENTER);
action.perform()

Access Selenium LocalStorage nodejs

Im trying to retrieve a value from a key using selenium, i've been searching for hours without anybody or anything telling me how i could do that,
What im trying to retrieve looks like this which i obtained while typing F12 : https://i.imgur.com/xYSHnnC.png
Which is on the client side.
You can use this:
driver.executeScript(
"localStorage.getItem(arguments[0])", key
);
Try this:
window.localStorage.getItem("BrowserHandoffStore");
Example here:
window.localStorage.setItem("test", false);
window.localStorage.getItem("test")
Output:
false
for who maybe still are looking for the solution:
you can use web driver executeScript
async function(localStorageFieldName){
await driver.executeScript(function(){
return localStorage.getItem(arguments[0])
},localStorageFieldName)
}
reference to executeScript : link

Resources