How to locate the input within div
The desired <input>
element is Ember.js based element so to identify the element you need to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:
Using
CSS_SELECTOR
:search = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#nav-typeahead-wormhole input[placeholder='Recherche']")))
Using
XPATH
:search = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='nav-typeahead-wormhole']//input[@placeholder='Recherche']")))
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
How to get all child inputs of a div element (jQuery)
Use it without the greater than:
$("#panel :input");
The >
means only direct children of the element, if you want all children no matter the depth just use a space.
javascript get all inputs inside div including select and textarea
Use jQuery and the :input
pseudo selector:
$('.output-shortcodes').find(':input');
That simple.
https://api.jquery.com/input-selector/
Or wrap it in a <form>
, then you can use:
document.getElementById("outputForm").elements...
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements
How to position an input field inside of a DIV
Simply add top: 50%
and transform: translateY(-50%)
to input
.
What this will do is:
transform: translateY(-50%)
will move theinput
element to its top, half of itsheight
.top: 50%
will center theinput
element.
div { height: 100px; width: 600px; margin-top: 10px; margin-left: auto; margin-right: auto; box-shadow: 2px 2px 5px gray;}input { position: relative; display: block; float: right; margin: auto; padding: 0px; top: 50%; transform: translateY(-50%);}#millitary_conflict { background-color: #FF6666;}#treasury_contents { background-color: #FFFFCC;}#wonder { background-color: #FFD633;}#civillian_structures { background-color: blue;}#commercial_structures { background-color: #FFFF66;}#guilds { background-color: purple;}#scientific_structures { background-color: green;}
<div id="millitary_conflict">Millitary Conflict <input type="number" value="0" "required"></div><div id="treasury_contents">Treasury Content</div><div id="wonder">Wonders</div><div id="civillian_structures">Civillian Structures</div><div id="commercial_structures">Commercial Structures</div><div id="guilds">Guilds</div><div id="scientific_structures">Scientific Structures</div>
Get all input fields inside div (without JS library)
document.getElementById('mydiv').getElementsByTagName('input')
Find input value inside child div
You were close. .parent()
only goes up one level (to the parent). Instead, you could change that to .closest()
or .parents()
.
Ex:
$(this).closest('div.content').find('input').val();
$('button').click(function() { console.log( $(this).closest('div.content').find('input').val() );});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div class="main"> <div class="content"> <input type="text" value="Hello World..."> <div class="subContent"> <button id="myButton">Get Input Value</button> </div> </div> <div class="content"> <input type="text" value="Hello World..."> <div class="subContent"> <button id="myButton">Get Input Value</button> </div> </div></div>
Find the number of <input> in an Div tag
Why always the jquery solutions ?
There is nothing wrong with using jquery, but including a JS library to count some elements is serious overkill.
Native javascript:
var inputCount = document.getElementById('divId').getElementsByTagName('input').length;
Can't find input element within div, selenium java eclipse
You need
driver.findElement(By.cssSelector("input[value=\\"Save and Return\\"]"));
Tell me if it doesn't work. Give more details about the errors. I might have mistaken about the escape characters \\ in the string.
Related Topics
Python Super :Typeerror: _Init_() Takes 2 Positional Arguments But 3 Were Given
Numpy Distance Calculations of Different Shaped Arrays
Stripping Non Printable Characters from a String in Python
How to Extract Address from Raw Text Using Nltk in Python
Getting the Bounding Box of the Recognized Words Using Python-Tesseract
Unable Log in to the Django Admin Page With a Valid Username and Password
Webscraping Financial Data from Morningstar
Pyqt: Getting Widgets to Resize Automatically in a Qdialog
How to Set Proxy Authentication (User & Password) Using Python + Selenium
Print a List of Space-Separated Elements
Pandas: Calculate the Percentage Between Two Rows and Add the Value as a Column
Find All CSV Files in a Directory Using Python
How to Pass a .Txt File to a Function in Python
How Does the Code Prints 1 2 6 24 as Output and Not 24 6 2 1
How to Remove Commas and Dots of Individual Word in Two Dimensional List