Selenium can't find fields with type number
First off, I think you have some confusion regarding those frameworks. Cucumber is a BDD framework, which doesn't automate browsers in any way, so this question has nothing to do with it (This is why I removed it from your question title).
Looks like you are using Capybara, which is an ATDD framework. You might probably consider showing us the Capybara code you use in order diagnose your problem.
Under the hood, I assume you use Selenium WebDriver, I can confirm that Selenium works fine with <input type="number">
(Tested with Firefox 28, which is the one selenium-webdriver (2.41.0) supports to).
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
DEMO_PAGE = <<-eos
data:text/html,
<input class="numeric integer required" id="application_form_age" min="0" name="application_form[age]" size="50" step="1" type="number">
eos
driver.get(DEMO_PAGE)
driver.find_element(:tag_name, 'input').send_keys('25')
So you might want to create a similar demo using Capybara to test this functionality.
If the demo works, then we need take a closer look at your application.
Othwewise, please raise a ticket for Capybara developers.
Can't enter text in search field with Selenium
To enter the text brand in Search Field you can use the following code block :
search_field = browser.find_element_by_xpath("//td[@class='searchArea']/div[@class='grid-area-filter-item']//input[@class='text-field searchBox' and contains(@class,'text-field-')]")
search_field.clear()
search_field.send_keys('brand')
SELENIUM Can't access payment form/fields
The element is in a frame (i.e. a webpage within a webpage). Selenium will look for elements in the page it has loaded and not within frames. That's the problem.
To solve this we just need a bit more code, which will tell Selenium to look in the frame.
The example you've given is several pages deep into a shopping cart, so I'm going to use a much more accessible example instead: the mozilla guide to iframes.
Here is some code to open that page and then click the CSS button within the frame:
from selenium import webdriver
import time
browser = webdriver.Chrome()
browser.get(r"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe")
time.sleep(5)
browser.switch_to.frame(browser.find_element_by_class_name("interactive"))
css_button = browser.find_element_by_id("css")
css_button.click()
browser.switch_to.default_content()
There are two lines that are important. The first one is:
browser.switch_to.frame(browser.find_element_by_class_name("interactive"))
That finds the frame and then switches to it. Once we have done that, any code that looks for elements will be looking in the frame and not in the page that we navigated to. That is what you need to do to access the number
element. In your example the class of the frame is card-fields-iframe
, so use that instead of interactive
.
The second important line is:
browser.switch_to.default_content()
That reverts the previous line. So now Selenium will be looking for elements within the page that we navigated to. You'll want to do that after interacting with the frame, so that you can continue through the shopping cart.
Selenium unable to find a specific field
You would need to implement wait
or fluentwait
. After clicking
WebElement more = driver.findElement(By.id("more_tweet_link"));
more.click();
The webdriver tries to interact with the webelement (.id("tweet_url_2")
) instantly (look at error message)
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"tweet_url_2"}
Command duration or timeout: 30 milliseconds # Fails in 30 milliseconds
The reason it fails is, the webelement .id("tweet_url_2")
is NOT present till the more_tweet_link
is clicked.
Related Topics
Understanding Usage of Symbols in Routes.Rb Files
Rails + Google Calendar API Events Not Created
Ruby Was-Sdk V2:Seahorse::Client::Networkingerror Exception: Ssl_Connect
Ruby Before_Validation Triggers Infinite Loop of Call Back
Ruby on Rails Updating Heroku Dynamic Routes
Use Variable in Parameter Ruby on Rails
How to Check If a Specific Key Is Present in a Hash or Not
List of All/Best Gems for Ruby
Create a Ruby Method That Accepts a Hash of Parameters
Error When Pushing to Heroku - ...Appear in Group - Ruby on Rails
Using Sed to Append Lines to File During Vagrant Provisioning
How to Count the Frequencies of the Letters in User Input
How to Specify Rvm Gemsets for Rails Gem Whenever
Slicing of Arrays in Ruby Returns Different Result - Nil VS. Empty Array
When Trying to Run Rspec, I Get "Uninitialized Constant Activemodel"