Selenium send_keys doesn't send uppercase R within the input bar - python

I'm using selenium 4.1.0 and I'm trying to send 'CRISTIAN' in an input bar through
input_bar.send_keys('CRISTIAN')
But it shows 'CISTIAN' in the bar.
I've tried also tried:
ActionChains(driver).click(input_bar).send_keys('CRISTIAN', Keys.ENTER).perform()`
But I get the same result. I checked all the uppercase letters and I figured out that only R have this problem. Any suggestions? Does it depends on this version of Selenium?
HTML of the input bar:
<div _ngcontent-qhp-c128="" cdkdroplist="" cdkdroplistorientation="horizontal" cdkdroplistdisabled="" class="cdk-drop-list d-flex flex-1 cdk-drop-list-disabled" id="cdk-drop-list-16"><input _ngcontent-qhp-c128="" cdkdrag="" data-bp="input" class="cdk-drag comp-input mt-2 cdk-drag-disabled" placeholder="Aggiungi elemento"><!----><!----><!----><!----></div>

The desired element is a Angular element, to send a character sequence 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, "div[id^='cdk-drop-list'][cdkdroplistorientation='horizontal'] input[class*='cdk-drag'][data-bp='input'][placeholder='Aggiungi elemento']"))).send_keys('CRISTIAN')
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#cdkdroplistorientation='horizontal' and starts-with(#id, 'cdk-drop-list')]//input[contains(#class, 'cdk-drag') and #data-bp='input'][#placeholder='Aggiungi elemento']"))).send_keys('CRISTIAN')
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

How to use python selenium to click this element with text bb1

<yt-formatted-string id="channel-title" class="style-scope ytd-account-item-renderer">bb1</yt-formatted-string>
below one is a dangerous find element by full x path because the index might change
self.driver.find_element_by_xpath('/html/body/ytd-app/ytd-popup-container/iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div/ytd-account-item-section-renderer/div/ytd-account-item-renderer[4]/paper-icon-item/paper-item-body/yt-formatted-string[1]').click()
To click on the element with text as bb1 you can use either of the following Locator Strategies:
Using css_selector:
self.driver.find_element_by_css_selector("yt-formatted-string.style-scope.ytd-account-item-renderer#channel-title").click()
Using xpath:
self.driver.find_element_by_xpath("//yt-formatted-string[#class='style-scope ytd-account-item-renderer' and #id='channel-title'][text()='bb1']").click()
Ideally, to click on 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(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "yt-formatted-string.style-scope.ytd-account-item-renderer#channel-title"))).click()
Using XPATH:
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//yt-formatted-string[#class='style-scope ytd-account-item-renderer' and #id='channel-title'][text()='bb1']"))).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
References
You can find a couple of relevant detailed discussions in:
How to click a link within youtube comment using python selenium

Python Selenium - Any way to get send text within this textbox?

I'm tring to select a textbox to input some data into it, the problem is i don't know how to get it's element:
This is what i get whem i do inspect on it:
<input class=" input" maxlength="255" type="text" aria-describedby="" placeholder="" id="8624:0" data-aura-rendered-by="8628:0" data-interactive-lib-uid="28">
The thing is that this is basically to fill forms, and id, rendered by, and uid numbers change.
Is there anything i could try?
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.input[type='text'][data-aura-rendered-by][aria-describedby]"))).send_keys("Smece")
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#class=' input' and #type='text'][#data-aura-rendered-by and #aria-describedby]"))).send_keys("Smece")
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

Selenium not able to click on Get Data button on using Python

I am scraping data from this website . The element is below and geckodriver
<img class="getdata-button" style="float:right;" src="/common/images/btn-get-data.gif" id="get" onclick="document.getElementById('submitMe').click()">
but can't get selenium to click it tried even xpath, id but not luck
is there any fix or work around to get it done?
To click on the element Get Data you can use either of the following Locator Strategies:
Using css_selector:
driver.find_element_by_css_selector("img.getdata-button#get").click()
Using xpath:
driver.find_element_by_xpath("//img[#class='getdata-button' and #id='get']").click()
Ideally, to click on 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, "img.getdata-button#get"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[#class='getdata-button' and #id='get']"))).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
You should probably try by id
driver.find_element(By.ID, 'get').click()

How can I click a href button using python 3.8 selenium?

The problem:
I'm trying to click this href here:
Fail attempts:
I tried to use these to no avail
driver.find_element_by_link_text('Join').click()
driver.find_element_by_partial_link_text('href').click()
You can use xpath instead of link text.
driver.find_element_by_xpath('//a[contains(text(), "John"]').click()
Or add space in front of John.
driver.find_element_by_link_text(' Join').click()
To click on the element with text as Join you can use either of the following Locator Strategies:
Using partial_link_text:
driver.find_element_by_partial_link_text("Join").click()
Using xpath:
driver.find_element_by_xpath("//a[contains(., 'Join')]").click()
Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using PARTIAL_LINK_TEXT:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Join"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., 'Join')]"))).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

Python, Selenium: how to click on javascript:void(0) element

I have an "onclick" element in a webpage,
<a href="javascript:void(0)" onclick=
"toIndexHtml('3','http://xxxxxxxxxxx/trade','0')">
<i></i>
<span></span>
trade
</a>
It is shown in the webpage as a button and I want to click on it, I tried to search for it using the following code:
driver.find_element_by_xpath("//a[contains(#onclick,'toIndexHtml')]").click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH,"/html/body/div/ul/li[3]/a"))).click()
Both are not working, please suggest if there is any other ways! Thanks in advance!
P.S.: I am using Chrome WebDriver and Chrome v64.
Your first locator looks perfect and should have worked.
Ideally, to click on 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, "a[onclick^='toIndexHtml']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[starts-with(#onclick,'toIndexHtml')]"))).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

Categories