I'm new to Selenium and trying to automate entering data. Im trying to grab the ID and then click the textbox to send data, but i keep getting an error message. I tried the Xpath also but it doesn't seem to be working.
here is my code.
product = driver.find_element_by_id("(improved-inventory/js/extension-providers/ItemComboBox_0)[2]")
product.click()
product.send_keys("027459087093")
product.send_keys(Keys.RETURN)
Any Help would be Appreciated. Here is the HTML im currently taking the id from the input Class. When i called product.isdisplayed() it prints false.
<div class="dijitInline dijitTextBox dijitComboBox quickfill qfComboBox dijitValidationTextBox"
id="widget_improved-inventory/js/extension-providers/ItemComboBox_0"
role="combobox" aria-haspopup="true" data-dojo-attach-point="_popupStateNode" widgetid="improved-inventory/js/extension-providers/ItemComboBox_0"
aria-disabled="false" aria-owns="improved-inventory/js/extension-providers/ItemComboBox_0_popup" > == $0
<input class="dijitReset dijitInputInner" type="text" autocomplete="off"
data-dojo-attach-point="textbox,focusNode" role ="textbox" placeholder="Enter Text"
tabindex="0" id="improved-inventory/js/extension-providers/ItemComboBox_0" value aria-label="Enter Text:" aria-invalid="false" aria-disabled="false">
Try waiting until input field is clickable:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver, timeout=30)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".dijitReset.dijitInputInner")))
product = driver.find_element_by_css_selector(".dijitReset.dijitInputInner")
product.click()
product.send_keys("027459087093")
product.send_keys(Keys.RETURN)
Also, fix your locator.
Related
I'm trying to click on a checkbox filter on a website with selenium python. This is a part of its HTML code linked to one of the checkbox options.
<div class="shopee-checkbox" bis_skin_checked="1">
<label class="shopee-checkbox__control">
<input type="checkbox" name="" value="Jabodetabek">
<div class="shopee-checkbox__box" bis_skin_checked="1">
<i> </i>
</div>
<span class="shopee-checkbox__label">Jabodetabek</span>
</label>
</div>
I tried following, but it didn't work.
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://shopee.co.id/search?keyword=baju%20laki-laki')
time.sleep(5)
driver.find_element(By.XPATH, "//input[#value='JABODETABEK']").click()
I read the answers to similar questions, mostly they suggest using 'id' and 'name' to find the element. However, in this input tag, there are only 'type' and 'value'.
Here is one way to select that checkbox:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
[...]
wait = WebDriverWait(driver, 25)
[..]
wait.until(EC.element_to_be_clickable((By.XPATH, '//span[text()="Jabodetabek"]'))).click()
print('clicked on Jabodetabek')
Selenium documentation can be found here.
#value for the checkbox in the xpath is incorrect. The selenium web locator techniques are case sensitive. So make sure to use exact values while identifying objects. Changing your xpath to below would fix the issue.
driver.find_element(By.XPATH, "//input[#value='Jabodetabek']").click()
Hi I cant get my selenium code to find this element in a page, it appears after ive used code to click a button on a page which opens up a form under the button.
Im looking to try get it to click on this input text box
<input id="number" class="iField" type="text" name="number">
My code
driver1.implicitly_wait(10)
driver1.until(EC.visibility_of_element_located(By.CSS_SELECTOR("input#number")))
button = driver1.find_element_by_xpath('//*[#id="number"]')
Website code
<form id="form" action="https://secureacceptance.cybersource.com/silent/embedded" method="post" autocomplete="off">
<div class="form-row">
<div class="left-col">
<label>No: </label>
</div>
<div class="right-col">
<input id="number" class="iField" type="text" name="number">
</div>
</div>
I've tried using Xpath, name Etc, but keep getting the unable to locate element.
Edit
ive also tried this
num = WebDriverWait(driver1, 10).until(EC.visibility_of_element_located(By.XPATH("//*[#id='number']")))
num.click()
But get this error
Traceback (most recent call last):
File "c:\Users\OneDrive\coding\code.py", line 68, in
num = WebDriverWait(driver1, 10).until(EC.visibility_of_element_located(By.XPATH("//*[#id='number']")))
TypeError: 'str' object is not callable
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#number")))
element = driver.find_element_by_css_selector("#number")
element.click()
You have id, so you can also use find_element_by_id instead of find_element_by_css_selector:
element = driver.find_element_by_id("number")
element.click()
Please note that I am waiting till this element becomes actually clickable.
Also, I don't understand why you are using driver1. Use driver for all elements.
Try 2
The answer is easier than I thought. You are messing up with ()
num = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//*[#id='number']")))
Try 3 (more detailed)
wait = WebDriverWait(driver,10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[#id='number']")))
Check here how to use explicit waits https://selenium-python.readthedocs.io/getting-started.html
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
num = WebDriverWait(driver1, 10).until(
EC.visibility_of_element_located((By.XPATH,"//*[#id='number']")))
your webdriverwait syntax is incorrect use the above one , you should not call By.xpath but pass it as a tuple to the EC
also do not use implicit wait ,
I have been using selenium to try and automate competition entries on Gleam. I had posted a question earlier about problems with finding tags but I eventually got it working by finding the iframe. However, the class tag that I used to enter my FULL_NAME has disappeared and does not exist anymore. It was the only tag that made the input tag unique.
So my question is, are the HTML tags changing when I reload the page? If so, why? and how can I distinguish between input tags when everything about them (i.e. id, name, class etc.) is exactly the same?
Here is my code if anyone wants to try and automate this site:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Chrome('/Users/<MY_NAME>/Documents/Automate_Login_py/chromedriver')
browser.get(('https://gleam.io/contest/airpods-pro'))
frame= "GleamEmbedzcR0I"
browser.switch_to.frame
# The below #class tag is not showing anymore
enterName = browser.find_element_by_xpath("//input[#class= 'ng-empty ng-invalid ng-invalid-required ng-valid-pattern ng-dirty ng-valid-parse ng-touched']")
enterName.send_keys('John Smith')
Edit: added HTML code
<input id="contestant[name]" name="name" ng-model-options="{ debounce: 300 }" ng-model="contestantState.form.name" ng-pattern=".*" placeholder="Alice Smith" required="" style="width: 246px" type="text" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required ng-valid-pattern">
As the id is present in the HTML structure, you can use that to get your element.
enter_name=browser.find_element_by_id("contestant[name]")
enter_name.send_keys("John Smith")
I am trying to login to a site www.bet365.com
I am able to send the login information for the username, however the password box is split into both a visible and hidden element for security.
How am I able to send the password to the box in order to automate login?
I have tried accessing the visible element however when passed not all characters of the password are received.
When attempting to pass to the hidden element no password is visibly sent.
I have also tried clicking the visible element before sending but this also did not work.
wait=WebDriverWait(driver,3)
userele=wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_UserNameWrapper input.hm-Login_InputField[type="text"]')))
userele.send_keys('xyz#gmail.com')
passwdele=wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_PasswordWrapper input.hm-Login_InputField.Hidden[type="password"]')))
passwdele.send_keys('xxxxxxxxxxx')
btnelement=wait.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_PasswordWrapper button.hm-Login_LoginBtn')))
btnelement.click()
Here is the main code for the elements on the bet365 page
<div class="hm-HeaderModule_UserAdmin ">
<div class="hm-Login ">
<div class="hm-Login_UserNameWrapper ">
<input type="text" class="hm-Login_InputField ">
<div class="hm-Login_InputText ">Join Now</div></div>
<div class="hm-Login_PasswordWrapper ">
<input type="text" class="hm-Login_InputField ">
<input type="password" class="hm-Login_InputField Hidden ">
<button tabindex="0" class="hm-Login_LoginBtn ">GO</button>
<div class="hm-Login_InputText ">Lost Login?</div></div></div></div>
Only the username passing currently works.
Well, you can send the password in visible input like this :
Code :
driver = webdriver.Chrome(executable_path = r'chromedriverPath')
wait = WebDriverWait(driver,10)
driver.maximize_window()
driver.get("https://www.bet365.com/#/HO/")
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH,"//div[#title='New Customer Bonus']"))).click()
userele = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.hm-Login_UserNameWrapper input.hm-Login_InputField[type='text']")))
userele.send_keys('xyz#gmail.com')
passwdele = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.hm-Login_PasswordWrapper input.hm-Login_InputField[type='text']")))
passwdele.send_keys('xxxxxxxxxxx')
btnelement = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'div.hm-Login_PasswordWrapper button.hm-Login_LoginBtn')))
btnelement.click()
imports would be :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Let me know, if you are facing any problem.
You need to avoid invoking send_keys() to a hidden password box in all possible ways. However inducing WebDriverWait for the first element on the page you want to interact would be enough and you don't need to invoke WebDriverWait multiple times when interacting with <input> elements. You can try either of the following Locator Strategies:
Using CSS_SELECTOR:
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.hm-Login_UserNameWrapper>input.hm-Login_InputField[type='text']"))).send_keys('xyz#gmail.com')
driver.find_element_by_css_selector("div.hm-Login_PasswordWrapper>input.hm-Login_InputField:not(.Hidden)").send_keys("hello")
Using XPATH:
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='hm-Login_UserNameWrapper ']/input[#class='hm-Login_InputField ' and #type='text']"))).send_keys('xyz#gmail.com')
driver.find_element_by_xpath("//div[#class='hm-Login_PasswordWrapper ']/input[contains(#class, 'hm-Login_InputField') and not(#class='Hidden')]").send_keys("Jp1875")
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 have to find Input Tag for id of a web page in the following HTML code using python Selenium:
NOTE: I was not able to paste the code because of its complexity so sorry for that. Here is the page to look out the complete HTML Tree.
I want to insert username to the mentioned below input tag:
<input type="text" id="appleId" can-field="accountName" autocomplete="off"
autocorrect="off" autocapitalize="off" aria-required="true"
required="required" aria-labelledby="appleIdFieldLabel" spellcheck="false"
autofocus="" ($focus)="appleIdFocusHandler()"
($keyup)="appleIdKeyupHandler()" ($blur)="appleIdBlurHandler()" class="si-
text-field form-textbox " placeholder="Apple ID">
Currently, I am using mentioned below code by the means of element's xpath but it's returning an empty list:
from selenium import webdriver
import time
browser = webdriver.Chrome()
browser.get('http://www.icloud.com')
time.sleep(20)
ele = browser.find_elements_by_xpath('//*[#id="appleId"]')
# ele.send_keys('abc#icloud.com')
print ele
Result: []
I have tried every other find functions too but could not get any results.
Authorization form located inside an iframe. To be able to handle input fields, you should switch to that iframe:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium import webdriver
from selenium.webdriver.common.by import By
browser = webdriver.Chrome()
browser.get('http://www.icloud.com')
wait(browser, 10).until(EC.frame_to_be_available_and_switch_to_it("auth-frame"))
account_name = wait(browser, 10).until(EC.presence_of_element_located((By.ID, "appleId")))
account_name.send_keys('abc#icloud.com')