I am trying to login to a site and I am using FindElementById. In the following code the first part of using SendKeys works well but when trying to use the same technique for the password field, I get an error message which tells me that the element is not interactable
Sub Test()
Dim bot As New WebDriver
With bot
.AddArgument "--disable-notifications"
.Start "Chrome", "https://www.excelforum.com/excel-programming-vba-macros/"
.Get "/"
.FindElementById("navbar_username").SendKeys "username"
.FindElementById("navbar_password").SendKeys "password"
'.FindElementByName("vb_login_password").SendKeys "password"
Stop
End With
End Sub
You were pretty close. The Password field with id attribute as navbar_password is having the property:
style="display: none;"
So you won't be able to interact with the element.
To send a character sequence both to the User Name and Password field you can use either of the following Locator Strategies:
Using FindElementById():
.FindElementById("navbar_username").SendKeys "username"
.FindElementById("navbar_password_hint").SendKeys "password"
Using FindElementByCss():
.FindElementByCss("input#navbar_username").SendKeys "username"
.FindElementByCss("input#navbar_password_hint").SendKeys "password"
Using FindElementByXPath():
.FindElementByXPath("//input[#id='navbar_username']").SendKeys "username"
.FindElementByXPath("//input[#id='navbar_password_hint']").SendKeys "password"
References
You can find a couple of revelant discussions in:
Trying to fill text in input box with dynamic drop down
Need help to fill number into Chrome input box with Selenium
Try referring this webpage
The page you are trying to access has added a web element over another web element. i.e web element of id navbar_password_hint over web element of id navbar_password. Try referring above link to solve your problem.
This happens when the element state is not clickable. You have to use webdriver wait property and make sure that element state is clickable
WebDriverWait wait= new WebDriverWait(driver, 10);
WebElement e= wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element")));
e.click();
Related
I want to automate some functions that I usually do on Trello, like create boards and lists.
I downloaded selenium IDE from chrome. Now, I can enter on trello's website and login with my password.
But I don't know how to click on a board.
I have a ul list and I want to find the board by name and click.
Public Sub seleniumtutorial()
Dim bot As New SeleniumWrapper.WebDriver
bot.Start "chrome", "https://trello.com/login"
bot.get "/"
bot.Type "name=user", "biaverly#id.uff.br"
bot.Type "name=password", "mypassword"
bot.clickAndWait "id=login"
OK UNTIL HERE
This is where I want do click
(https://scontent.fsdu13-1.fna.fbcdn.net/v/t1.15752-9/61126356_2783547018382386_4366937053661757440_n.png?_nc_cat=110&_nc_ht=scontent.fsdu13-1.fna&oh=ac6b0ac6acc49e8ca3c2bcb54d105afa&oe=5D62AC25)
and I want do find by the name
(https://scontent.fsdu13-1.fna.fbcdn.net/v/t1.15752-9/60763397_620930688408674_8385622658426863616_n.png?_nc_cat=109&_nc_ht=scontent.fsdu13-1.fna&oh=02f1f5766e149f32e1879a553c7a9d84&oe=5D9B1F82)
You can't use className for that web element bec. it's made up from diff class. instead of class, you can use css selector to locate that element.
try this css selector .boards-page-board-section .mod-no-sidebar
you can use this css selector to locate by text div[title='urtext']
While trying to give user name and password to the url "https://connect.garmin.com/signin/" using xpath in chrome webdriver in python, I'm getting the error "no such element: unable to locate element".
Xpath i used is
driver.find_element_by_xpath("//*[#id='username']").send_keys("usernameusername")
You might need to wait for the element to become clickable:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[#id='username']")).send_keys('usernameusername')
Also, use single quotes around 'username'.
This is the code snippet for chroome:
driver.get("https://www.youtube.com/")
driver.find_element_by_xpath('//*[#id="search"]').send_keys("kao")
driver.find_element_by_xpath('//*[#id="search-icon-legacy"]').click()
The browser automatically opens Youtube and searches for the passed string[which is the task I intend to do]
The main problem appears when i start using firefox.The page loads properly.I am basically using the same code but every time I run it, it throws the following error:
Message: Element <g id="search"> is not reachable
I cannot pass any string to the search bar or even click it.
There is a slight error in the xpath //*[#id='search'] that it returns two elements as in below screen. The reason being the * in the above xpath acts as a wild card and matches the other ytd-searchbox<id="search"> tag in the page. The same is true for //*[#id="search-icon-legacy"].
So you must try changing to the xpath like below to locate the web elements uniquely
//input[#id='search']
//button[#id='search-icon-legacy']
Errored Xpath:
Your Xpath is not correct. It's Unable to locate search field and buttton
You can use this one
driver.get("https://www.youtube.com/")
driver.find_element_by_xpath("//input[#id='search']").send_keys("kao")
driver.find_element_by_xpath("//button[#id='search-icon-legacy']").click()
I am unable to input text into the Booking Number textbox in: https://www.hmm21.com/cms/business/hongkong/export/vgmWithoutLogin/index.jsp
This is the html of the textbox using inspect on chrome:
<input style="width:200px;text-transform:uppercase;ime-mode:disabled;" type="text" maxlength="12" name="bookingNumber" value="">
This is the code I am using for now:
element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='bookingNumber']"))).send_keys('test')
I tried many other methods as well, like selecting using CSS Selector, absolute xpath, but I just cannot seem to be typing anything into the textbox.
I also tested the xpaths and CSS Selectors using ChroPath, a few other chrome extensions, xPath Finder on Firefox as well, and they all seemed to be working.
Would appreciate if anyone could help. Thanks.
To send a character sequence to the element associated with the text Booking Number as the desired elements are 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 the following solution:
Using CSS_SELECTOR:
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#_frame1[src='/ebiz/ebooking/vgm/indexWithoutlogin.jsp']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='bookingNumber']"))).send_keys('Rong Heng')
Using XPATH:
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[#id='_frame1' and #src='/ebiz/ebooking/vgm/indexWithoutlogin.jsp']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='bookingNumber']"))).send_keys('Rong Heng')
Here you can find a relevant discussion on Ways to deal with #document under iframe
Try clicking the element before sending keys, You can also excute a JavaScript to modify it's value.
.click()
Also If the input is displayed through JavaScript wait for the element to be present and not clickable.
.presence_of_element_located()
You should switch the iframe first, use
WebDriverWait(self.driver, 10).until(EC.frame_to_be_available_and_switch_to_it(self.driver.find_element_by_id('_frame1')))
Because the Booking Number textbox input element is in a new iframe named '_frame1'.
Hope it will help you.
This element is inside iframe as ChroPath suggested. So first you will have to switch to iframe and perform the action. Sometime if sendKeys doesn't work on input box then try clear/click() method before sending keys in box.
I am trying to click on an icon in a web page. This is the element I am attempting to click:
<a class="Button ButtonIcon IconOnly DataSelector NormalState"
id="ze6402ef81ea54445aec5dab8790c781f" tabindex="0"><span class="Icon"></span>
<span class="Text"></span></a>
I have no problem interacting with the code below:
browser.find_element_by_css_selector('ze6402ef81ea54445aec5dab8790c781f').click()
The problem is that the id is dynamic with each session. I have attempted a workaround with the following code with no success:
browser.find_element_by_xpath("//a[span/#class='Text']").click()
and
browser.find_element_by_xpath("//a[span/#class='Icon']").click()
Afterwards, I noticed that the element needs to be in a hover state in order to be clicked. So next, I used ActionChains to try to simulate a hover state -- again, with no success:
actions=ActionChains(browser)
element=browser.find_element_by_css_selector("//a[span/#class='Icon']")
actions.move_to_element(element).click().perform()
Then, I tried to TAB to the element via send_keys and ActionChains -- but it ended up cycling rapidly through page, instead of one element at a time:
actions.send_keys(Keys.TAB)
I wanted to put in my due diligence before posting my issue. Any assistance is appreciated - Thank you.
As you mentioned, you don't have a problem with the following line of code:
browser.find_element_by_css_selector('ze6402ef81ea54445aec5dab8790c781f').click()
But the only issue here is that the id is dynamic, so we can use the class attribute to construct an unique cssSelector or an unique xpath as follows:
cssSelector :
driver.findElement(By.cssSelector("div.Button.ButtonIcon.IconOnly.DataSelector.NormalState"));
xpath :
driver.findElement(By.xpath("//div[#class='Button ButtonIcon IconOnly DataSelector NormalState']"));
Use these XPaths:
//span[#class='Text']
//span[#class='Icon']
Yours were formatted incorrectly.