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
Related
I am trying to click this button with Selenium:
<button class="MuiButtonBase-root MuiButton-root jss38 MuiButton-contained MuiButton-containedPrimary" tabindex="0" type="button" data-test="unifiedCrazyButton"><span class="MuiButton-label">Let's get crazy</span><span class="MuiTouchRipple-root"></span></button>
I can't do it by the class name, because there are other buttons with the same class name, and also the xpath value in this format:
/html/body/div[10]/div[3]/div/div[3]/button[2]
keeps changing which is unfortunate.
The only identifying factor seems to be
data-test="unifiedCrazyButton"
How can I click this button with Selenium?
The desired element is a dynamic element, so to click on the clickable 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, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-test='unifiedCrazyButton'] span.MuiButton-label"))).click()
Using XPATH:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[#data-test='unifiedCrazyButton']//span[#class='MuiButton-label' and contains(., 'get crazy')]"))).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 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
<textarea style="font-size: 1.2em" ng-model="applications" ng-list=" " ng-trim="false" rows="15" cols="70" class="ng-valid ng-dirty ng-valid-parse ng-touched"></textarea>
This is the text area tag. I want to insert some text into the text area. How can I proceed with the python code for the selenium webdriver.
I tried:
driver.find_element_by_class_name("ng-pristine ng-valid ng-touched")
Please help me out.
To send a character sequence to the element you can use either of the following Locator Strategies:
Using css_selector:
driver.find_element_by_css_selector("textarea.ng-valid.ng-dirty.ng-valid-parse.ng-touched[ng-model='applications']").send_keys("samhith gardas")
Using xpath:
driver.find_element_by_xpath("//textarea[#class='ng-valid ng-dirty ng-valid-parse ng-touched' and #ng-model='applications']").send_keys("samhith gardas")
However the desired element is a Angular 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, "textarea.ng-valid.ng-dirty.ng-valid-parse.ng-touched[ng-model='applications']"))).send_keys("samhith gardas")
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[#class='ng-valid ng-dirty ng-valid-parse ng-touched' and #ng-model='applications']"))).send_keys("samhith gardas")
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
driver.find_element_by_class_name("ng-pristine.ng-valid.ng-touched").
Or
driver.find_element_by_xpath("//textarea[#claaa='ng-pristine ng-valid ng-touched']")
Class with space indicates multiple classes , so you have to replace space with dot in find_element_by_class
Else use xpath and find the element that matches absolute attribute value of the class
Trying to make my bot click on a submit button.
<div class="usertext-buttons">
<button type="submit" onclick="" class="save">save</button>
<button type="button" onclick="return cancel_usertext(this);" class="cancel" style="display:none">cancel</button>
<span class="status"></span></div>
I want to get the second row element with the type="submit"
driver.find_element_by_xpath doesn't work since the xpath is different for every post. What can I pull here that generally works?
To click on the element with text as save you can use either of the following Locator Strategies:
Using css_selector:
driver.find_element_by_css_selector("button.save[type='submit'][onclick]").click()
Using xpath:
driver.find_element_by_xpath("//button[#class='save' and text()='save'][#type='submit' and #onclick]").click()
Ideally, to click on 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, "button.save[type='submit'][onclick]"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[#class='save' and text()='save'][#type='submit' and #onclick]"))).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
Try using css selector:
driver.find_element_by_css_selector('div.usertext-buttons > button[type=submit]').click()
I am trying to use Selenium in Python to try and log into this website
https://commerce.spscommerce.com/auth/login/
All of the xpath's I have tried were not able to locate the element.
driver = webdriver.Chrome()
driver.get("https://commerce.spscommerce.com/auth/login/")
driver.find_element_by_xpath('//input[#id="username"]').send_keys("test")
I tried using name, type and class but have not been able to locate the element.
Here is the HTML I got from inspect element
<input id="username" name="username" type="email" required="" ng-model="ctrl.email" ng-
blur="ctrl.checkEmail($event, ctrl.email)" ng-focus="ctrl.resetEmailBoolean()" autofocus=""
test="login-username" class="ng-pristine ng-valid ng-not-empty ng-valid-email ng-valid-required ng-touched">
Any Ideas on what path to use to locate the element and send the username/password? Thanks so much for the help.
The Email Address field is within an <iframe> so you have to:
Induce WebDriverWait for the desired frame to be available and switch to it.
Induce WebDriverWait for the desired element to be clickable.
You can use either of the following Locator Strategies:
Using CSS_SELECTOR:
driver.get('https://commerce.spscommerce.com/auth/login/')
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://commerce.spscommerce.com/auth-app']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#username"))).send_keys("test")
Using XPATH:
driver.get("https://www.nasdaq.com/symbol/msft/interactive-chart?timeframe=5d")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(#src, 'edgar-chartiq')]")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='btn hideSmallIR stx-collapsible' and #id='dataTableBtn']/span[text()='Data Table']"))).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
Browser Snapshot:
Reference
You can find a relevant discussion in:
Ways to deal with #document under iframe
Switch to an iframe through Selenium and python