Add "Reply" to Twitter Reply Box Using jQuery - javascript

I am trying to add predefined text to the Twitter "reply" box:
but for some reason no matter what I try it won't work. Here is my code:
const element = document.querySelector("div.public-DraftEditorPlaceholder-root");
element.remove();
span.innerHTML = '<span data-text="true">' + s + '</span>';
it adds in the reply e.g.
But it does it in a way where the reply stays "disabled" until I key in text, but then it deletes the message my script added.
This is for a google chrome extension

Related

search input on JAVASCRIPT

how to make an input like on the google site? I need that after entering the texts and in the input, Google opens with the desired request.
on JAVASCRIPT
google's input
1
2
my input(html)
<input class="finder" type="search" placeholder="Search in Google">
You can add an event listener to let's say a button.
When that button is clicked, the value in your search field will be added to the end of a Google search link.
However, since you can expect people to type sentences (and urls don't use spaces), you can use replace() to replace all spaces with, in our case, a + (url format for spaces is %20, but spaces in queries are commonly replaced with a + character).
Lastly, you can use window.open(), to open a new window that uses our link.
UPDATE: You can use a keypress as a trigger for the eventlistener, and then check if the entered key is an "Enter", that way you don't need a button.
Here's an example:
SEARCH_GOOGLE_VALUE is the textfield the user can type
const SEARCH_GOOGLE_VALUE = document.getElementById('SEARCH_GOOGLE_VALUE');
SEARCH_GOOGLE_VALUE.addEventListener("keypress", (keyboard) => {
if (keyboard.key == "Enter") {
let value = SEARCH_GOOGLE_VALUE.value;
value = value.replace(' ', '+');
let link = "https://www.google.com/search?q=" + value;
window.open(link);
}
});
if you mean redirect to a google page after input this would work
document.querySelector('.finder').addEventListener('focusout',function(){
location.replace("https://www.google.com/search?q=" + document.querySelector('.finder').textContent);
});
this will send the user to a google page with the needed requests when they leave the input fild
if you need to make something simular but on your oun website the best option would be to send the user to a nother page with the query data in the url and some back end to construct and return a needed page.
or you could send a fetch and get info back on focus out

Selenium Python Shadow DOM input text

The website I am interacting with uses shadow DOMs. I can successfully interact with them for clicking buttons and in some cases can input text but I am currently stumped on this one.
The HTML looks like this
firefox html inspector view of one shadow dom input text box
I can input in the text fields with the following but the continue button doesn't enable for me to go to the next screen and if I manually click and place a space in the first box I get an error saying that to continue to the next page I need to fill in the second and third boxes (which have text but for some reason the webpage doesn't recognize that text is present). table with shadow dom inputs
shadowDOM1 = driver_local.execute_script("return document.querySelector('WN-input').shadowRoot.querySelector('input')")
str_valToSet = "arguments[0].value = '" + partNum + "';"
driver_local.execute_script(str_valToSet, shadowDOM1)
shadowDOM2 = driver_local.execute_script("return document.querySelectorAll('WN-input')[2].shadowRoot.querySelector('input')")
str_valToSet = "arguments[0].value = '" + str(num2buy) + "';"
driver_local.execute_script(str_valToSet, shadowDOM2)
shadowDOM3 = driver_local.execute_script("return document.querySelectorAll('WN-input')[1].shadowRoot.querySelector('input')")
str_valToSet = "arguments[0].value = '" + "CUSTX" + "';"
driver_local.execute_script(str_valToSet, shadowDOM3)
I was also able to click the text box input that is in the shadow root but when i go to send keys i get an error that "element is not reachable by keyboard". There is not a temporary overlay preventing me from typing, as far as i can tell there is not a permanent overlay, and I see no evidence of any attributes that would make it invisible to selenium (org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard: while sending text to FirstName field in Facebook)
fields = driver.find_elements(By.XPATH, '//tbody/tr/td/WN-input')
print("fields", fields)
print("field", fields[0])
shadowEl = expand_shadow_element(driver_local, fields[0])
print("shadowEl", shadowEl)
isVisible = WebDriverWait(shadowEl[1], maxDelay).until(EC.visibility_of_element_located((By.XPATH, "//input")))
print("isVisible", isVisible)
shadowEl[1].click()
time.sleep(2)
shadowEl[1].send_keys("blahblah")
In a different location within my code I successfully interact with a similar object this this (WN-input tag name) and was able to get it to open up the "next" button by typing some garbage text in a different input field that wasn't within a shadow DOM. When I try that technique for this case it blows away my text within my shadow DOM text input fields. I am not sure why this case seems to work and the case in question doesn't.
shadowDOM1 = driver_local.execute_script("return document.querySelector('WN-add-to-cart').shadowRoot.querySelector('WN-input')")
str_valToSet = "arguments[0].value = '" + str(num2buy) + "';"
driver_local.execute_script(str_valToSet, shadowDOM1)
try:
inputBox = WebDriverWait(driver_local, maxDelay).until(EC.element_to_be_clickable((By.XPATH, "//input[#placeholder='Search']")))
#inputBox = local_driver.find_element_by_xpath("//input[#placeholder='Search']")
inputBox.click()
inputBox.send_keys("text")
time.sleep(3)
After days of failed attempts and google search after google search I am finally ready to ask for help. Any thoughts?

Remove HTML before insertBefore jQuery

I have a field that inserts HTML when a user submits my form. If there is an error it inserts the error message before the form field. However, if the user submits multiple times it inserts multiple error messages, I would like to simply replace the error message so that it only appears once. I've tried to use replace but I couldn't get this way to work.
The form works via ajax so we don't reload the page to remove the errors, I need a way of replacing / removing them using jQuery.
Here is my jQuery code.
$('<p class="form-error" id="' + errorKey + 'ErrorMessage">' + json.errors[errorKey] + '</p>')
.insertBefore(('[name="' + errorKey + '"]'))
Select by id and remove:
$('#' + errorKey + 'ErrorMessage').remove();

Cefsharp to enter data to form

I need Cefsharp to do a small bit of automation. What I want to do is enter data into two textfield and then press a button. To do this I'm using javascript.
browser.ExecuteScriptAsync("var elems = document.getElementsByClassName('_fcn8k');");
browser.ExecuteScriptAsync("elems[0].click();");
Thread.Sleep(5000);
browser.ExecuteScriptAsync("var elems2 = document.getElementsByClassName('_kp5f7');");
browser.ExecuteScriptAsync("var elems3 = document.getElementsByClassName('_taytv');");
browser.ExecuteScriptAsync("elems2[0].value='" + userName + "';");
browser.ExecuteScriptAsync("elems2[1].value='" + userPassword + "';");
browser.ExecuteScriptAsync("elems[3].click();");
The code works, except for the fact that when I click the button the textfields are emptied and I get an error saying the data is wrong (since the fields are empty).
If I do it manually the data remains when the button is pressed. I really don't get why it disappears when I try to do this programmaticly.
Any ideas?

How do I replicate onclick button results when a user clicks a DIV?

I also have a text box where the user can enter a name and the objects associated to that user are returned via a query and displayed on the html page using
<div id="FriendsStuff"></div>
The code for the search function is
$(document).ready(function () {
$(document).on('click', '.username, #find_button', function (event) {
//debugger;
event.preventDefault();
friendName = $(this).is("button") ? null : $(this).text();
friendFeed(friendName);
});
});
I also have a div that lists the users (Instead of having to search for them) on the html page
<div id="container"></div>
Populated by this:
$('#container').append("<img class='images' src='" + imageURLs[j] + "'/>");
$('#container').append("<div class='username'>'" + Username[j] + "'</div>");
What I want the user to do is click on the name that is displayed on the page and replicate the same action as what happens if the user clicks the "find" button. Basically to return the associated results back to the page.
The example page is here,http://www.kudosoo.com/friendslist.html so for example the user clicks "dave" and the result is the same as if they'd entered "dave" into the text box and clicked "find"
How can I achieve this? Do I reference the container div within the onclick function?
I don't see a Dave at that link and I'm having a hard time following your question but I believe you're looking for .val and .trigger.
This would set the value of the input.
$('#friendsearch').val('Dave');
and then you trigger the click.
$('.btn-login').trigger('click');
You should consider putting these elements into a form.

Categories