I have one question on Selenium which is how can I enter text into textarea (wiki textarea)? Below is my original HTML, please help me to figure out this. Thank you very much!
<textarea class="textarea long-field wiki-textfield mentionable wiki-editor-initialised wiki-edit-wrapped" cols="60" id="comment" name="comment" wrap="virtual" data-projectkey="PE15" data-issuekey="PE15-2181" resolved="" style="min-height: 174px; max-height: 369px;"></textarea>
text_area = driver.find_element_by_id('comment')
text_area.send_keys("This text is send using Python code.")
As per the HTML you have provided to send character sequence into the text area you need to induce WebDriverWait as follows:
CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.textarea.long-field.wiki-textfield.mentionable.wiki-editor-initialised.wiki-edit-wrapped#comment"))).send_keys("Ben_C")
XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[#class='textarea long-field wiki-textfield mentionable wiki-editor-initialised wiki-edit-wrapped' and #id='comment']"))).send_keys("Ben_C")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Related
I have the following HTML structure and I am trying to use Selenium to enter a value
<div class="form-group justify-content-center d-flex">
<form id="main-form" class="form-inline" action="/pushData" method="post">
<input type="hidden" name="_token" value="bnePp0JmVaVYuaTIAfuVIGT2y7usVssX3vQrAGaz">
<input type="text" id="input-url" class="url-input" name="url" placeholder="Paste URL to shorten">
<button class="button main-btn main-btn_primary" id="button-submit">Cut</button>
</form>
</div>
Here is my code
driver.find_element_by_id("input-url").send_keys("test")
driver.find_element_by_id("button-submit").click()
I want to get this element and enter a value.
Select element by id:
inputElement = driver.find_element_by_id("input-url")
inputElement.send_keys('testing')
Now you can simulate hitting ENTER:
inputElement.send_keys(Keys.ENTER)
or if it is a form you can submit:
inputElement.submit()
Selenium 4.3.0: Deprecated find_element_by_* and find_elements_by_*
are now removed (#10712)
The following code will work:
[..]
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
[..]
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'input-url'))).send_keys('test')
button_to_be_clicked = browser.find_element(By.ID, 'button-submit')
button_to_be_clicked.click()
To send a character sequence to the <input> element you can use either of the following locator strategies:
Using css_selector:
driver.find_element(By.CSS_SELECTOR, "input.url-input#input-url[name='url'][placeholder='Paste URL to shorten']").send_keys("Phonex")
Using xpath:
driver.find_element(By.XPATH, "//input[#class='url-input' and #id='input-url'][#name='url' and #placeholder='Paste URL to shorten']").send_keys("Phonex")
Ideally to send a character sequence to the <input> element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.url-input#input-url[name='url'][placeholder='Paste URL to shorten']"))).send_keys("Phonex")
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#class='url-input' and #id='input-url'][#name='url' and #placeholder='Paste URL to shorten']"))).send_keys("Phonex")
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I'm trying to enter text into an address bar using the following code in python:
driver.find_element_by_xpath('//*[#id="esri_dijit_Search_0_input"]').send_keys('text')
However, it does not register anything when running without debugging. Could you please provide any solutions on how to input text into an address bar with the following html?
<form data-dojo-attach-point="formNode">
<input maxlength="128" autocomplete="off" type="text" tabindex="0" class="searchInput" value="" aria-haspopup="true" id="esri_dijit_Search_0_input" data-dojo-attach-point="inputNode" role="textbox" placeholder="Address or Grid Reference" title="Address or Grid Reference" style="width: 170px;">
</form>
The desired element is a dynamic element, so ideally to send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.searchInput[id^='esri_dijit_Search'][title='Address or Grid Reference']"))).send_keys("text")
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#class='searchInput' and starts-with(#id, 'esri_dijit_Search')][#title='Address or Grid Reference']"))).send_keys("text")
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I can't insert a value in field text in html formulary using Selenium Python:
I have this HTML:
<div data-react-toolbox="input" class="_2dBwA"><input type="text" placeholder="Endereço de e-mail" class="_2WvFs" role="input"><span class="fT1WI"></span></div>
and this XPath:
(Copy Xpath) //*[#id="root"]/div/div[2]/div[2]/div/input
and this:
(Copy outerHTML) <input type="text" placeholder="Endereço de e-mail" class="_2WvFs" role="input">
I did it, but dont worked:
[In]: login_name = 'Cassandra'
[In]: insert_login_name = driver.find_element_by_xpath('//input[#id="root"]')
[In]: insert_login_name.send_keys(login_name);
[Out]: NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[#id="root"]"}
After entering the text in this text field, the result would be in html 'values' = 'Cassandra'
<div data-react-toolbox="input" class="_2dBwA"><input type="text" placeholder="Endereço de e-mail" class="_2WvFs _3QmiH" role="input" value='Cassandra'><span class="fT1WI"></span></div>
What can i do? I'm new in that. Thanks
The desired element is a ReactJS enabled element so to send a character sequence with in the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-react-toolbox='input']>input[placeholder='Endereço de e-mail'][type='text']"))).send_keys(login_name)
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#data-react-toolbox='input']/input[#placeholder='Endereço de e-mail' and #type='text']"))).send_keys(login_name)
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Update
Seems it was a locale issue. Changing the value of placeholder attribute from Endereço de e-mail to E-mail address works perfecto.
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-react-toolbox='input']>input[placeholder*='mail'][type='text']"))).send_keys(login_name)
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#data-react-toolbox='input']/input[contains(#placeholder, 'mail') and #type='text']"))).send_keys(login_name)
Reference
You can find a relevant detailed discussion in:
Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome
Induce WebDriverWait and element_to_be_clickable() and following css selector.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver=webdriver.Chrome()
driver.get("https://www.atlasgov.com/login")
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'div[data-react-toolbox="input"] >input[placeholder="E-mail address"][role="input"]'))).send_keys("Cassandra")
Browser snapshot:
Updated Xpath.
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,'//div[#data-react-toolbox="input" and #class="_2dBwA"]/input[#role="input"]'))).send_keys("Cassandra")
OR
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,'(//div[#data-react-toolbox="input"]//input[#role="input"])[1]'))).send_keys("Cassandra")
The error message is pretty clear: selenium is unable to find the element at the given xpath. Since you have the element's id just use it directly instead of an xpath.
driver.find_element_by_id('root')
It is issue about wrong locator xpath. Although in given Html there is no element with ID as root but it seems there can be any parent node with ID as root Please try with given xpath based on provided html. Hope it will work:
driver.find_element_by_xpath("//input[#placeholder='Endereço de e-mail']");
how to press the "f_agreements_all" button ?
<label for="f_agreements_all">
<input type="checkbox" id="f_agreements_all">
<span></span>
<span class="permText">I accept all</span>
</label>
Unfortunately, finding "f_agreements_all" button and clicking it doesnt work. Span covers the whole button17x17px, when f_agreements_all is 16x16 under it. Do you know possible way to click it?
Using vanilla JS one way to do it would be:
const checkbox = document.getElementById('f_agreements_all');
checkbox.click();
Quickly looking at the Python Selenium 2 WebDriver API docs, one can try:
driver.find_element_by_id("f_agreements_all").click()
Can you please try below xpath :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
button=WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[#class='formCheckbox agreements all-agreements']//span[1]")))
button.click()
To click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solutions:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='f_agreements_all']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[#for='f_agreements_all']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I'm trying to click on this button to go to the next page, but for some reason, I'm unable to. I tried xpath, css, and class selectors as well as the data-trekkie-id attribute, but nothing I have tried worked. Any help? Code below:
<div class="step__footer" data-step-footer="">
<button name="button" type="submit" class="step__footer__continue-btn btn " data-trekkie-id="continue_to_shipping_method_button" aria-busy="false">
<span class="btn__content">
Continue to shipping method
</span>
</button>
</div>
As per the HTML to invoke click() method on the button with text as Continue to shipping method you need to induce WebDriverWait and you can use either of the following solutions:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.step__footer__continue-btn.btn[data-trekkie-id='continue_to_shipping_method_button']>span.btn__content"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[#class='step__footer__continue-btn btn' and #data-trekkie-id='continue_to_shipping_method_button']/span[#class='btn__content']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
This should work:
driver.find_element_by_xpath("//*[contains(local-name(), 'button') and contains(#class, 'step__footer__continue-btn')]").click()