How to Locate the Input Within Div

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:

  1. transform: translateY(-50%) will move the input element to its top, half of its height.

    enter image description here

  2. top: 50% will center the input element.

    enter image description here

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



Leave a reply



Submit