I want to locate and insert value inside a 'value' field.
As you can see the following HTML code the value is empty, I'm trying to locate the element to insert a new value to it but unable to find.
<input aria-label="" id="tab-shared-widget-2" class="" data-tb-test-id="auth-component-password-text-field-TextInput" type="password" value=""
I've tried to locate the element using XPath and by CSS Selector and for some reason my web driver still doesn't find the element using both ways.
susername = driver.find_element_by_css_selector("#tab-shared-widget-2")
susername.send_keys("Something")
spassword = driver.find_element_by_xpath("tab-shared-widget-2").get_attribute('value')
spassword.send_keys("Something")
Related
Web page has the following HTML without an ID - how do I set the value of the form?
<input name="loanxFindBorrower" onkeypress="if((window.event&&window.event.keyCode==13) ||
(event.which&&event.which==13 )){ findByBorrowerAction()}" type="text" size="25" value="">
I've tried
IE.Document.getElementByTagName("loanxFindBorrower").Value = "New Value"
Aswell as
IE.Document.getElementByTagName("loanxFindBorrower").Focus
IE.Document.getElementByTagName("loanxFindBorrower").Value = "NewValue"
Any help would be much appreciated
You should use getElementsByName() to get the element. It returns a collection, you'll need to specify the index to get the element you want.
For example, if it's the first element with name "loanxFindBorrower" in the page, the index is 0:
IE.Document.getElementsByName("loanxFindBorrower")(0).Value = "New Value"
im having trouble accessing element, here is my code:
driver.get(url)
desc = driver.find_elements_by_xpath('//p[#class="somethingcss xxx"]')
and im trying to use another method like this
desc = driver.find_elements_by_class_name('somethingcss xxx')
the element i try to find like this
<div data-testid="descContainer">
<div class="abc1123">
<h2 class="xxx">The Description<span data-tid="prodTitle">The Description</span></h2>
<p data-id="paragraphxx" class="somethingcss xxx">sometext here
<br>text
<br>
<br>text
<br> and several text with
<br> tag below
</p>
</div>
<!--and another div tag below-->
i want to extract tag p inside div class="abc1123", but it doesn't return any result, only return [] when i try to get_attribute or extract it to text.
When i try extract another element using this method with another class, it works perfectly.
Does anyone know why I can't access these elements?
Try the following css selector to locate p tag.
print(driver.find_element_by_css_selector("p[data-id^='paragraph'][class^='somethingcss']").text)
OR Use get_attribute("textContent")
print(driver.find_element_by_css_selector("p[data-id^='paragraph'][class^='somethingcss']").get_attribute("textContent"))
I need some help. Chrome (v 75.0.3770.100) using Selenium Basic ChromeDriver (v 75.0.3770.140) in Excel (2013) VBE. There's an input box which generates a dynamic list if the customer id# exists. I wish to fill in the customer id# then select from the dynamic drop down. But first step, I'm struggling to input my text to the box. I'm able to click on the box with
obj.FindElementById("selectcustTxt").Click
but when I try to fill in the box with:
obj.FindElementById("selectcustTxt").Value = "1111"
I get an error Run-time error '424': Object required
I tried the following FindElementByXPath with both .Value and .Text but get the same Run-time error '424': Object required
obj.FindElementByXPath("//input[#class='form-control cust-autosuggest ng-pristine ng-valid ng-touched'][#id='selectcustTxt']").Value = "1111"
Here's the HTML:
<div class="form-group search-field"><input id="selectcustTxt" type="text" class="form-control cust-autosuggest ng-valid ng-touched ng-dirty ng-valid-parse" autocomplete="off" plshholder="Enter Cust name" autocomplepte="off" ng-model="cust" suggest-type="custService" sh-autosuggest="custAddresses" data-validation="required">
To send a character sequence within the desired element you can use either of the following Locator Strategies:
Using FindElementByCss:
obj.FindElementByCss("input.form-control.cust-autosuggest.ng-valid.ng-touched.ng-dirty.ng-valid-parse#selectcustTxt").SendKeys ("1111")
Using FindElementByXPath:
obj.FindElementByXPath("//input[#class='form-control cust-autosuggest ng-valid ng-touched ng-dirty ng-valid-parse' and #id='selectcustTxt']").SendKeys ("1111")
Reference
You can find a couple of relevant discussions in:
How to send text to some HTML elements?
Need help to fill number into Chrome input box with Selenium
I want to get the value of the "tabindex" selector of this HTML code:
<input name="ctl00$ctl00$placeContent$placeTopContent$filter$textAccount" type="text" value="110111102" id="ctl00_ctl00_placeContent_placeTopContent_filter_textAccount" style="width: 130px;" data-kpxc-id="ctl00_ctl00_placeContent_placeTopContent_filter_textAccount" tabindex="-1">
I tried with it with the following code, but I only get the value of "value". How can I correctly check for it?
driver.find_element_by_xpath('//*['#id="ctl00_ctl00_placeContent_placeTopContent_filter_textAccount" and #tabindex]').get_attribute('value')
Use attribute tabindex and following code.
driver.find_element_by_xpath('//input[#id="ctl00_ctl00_placeContent_placeTopContent_filter_textAccount"]').get_attribute('tabindex')
You can also use css selector.
driver.find_element_by_css_selector('#ctl00_ctl00_placeContent_placeTopContent_filter_textAccount').get_attribute('tabindex')
I am trying to select the value from a dropdown box using vba, the code block for the dropdown box is as follows
<input type="text" id="form_autocomplete_input-1542902425322" list="form_autocomplete_suggestions-1542902425322" placeholder="Search keyword or select filter" role="combobox" aria-expanded="false" autocomplete="off" autocorrect="off" autocapitalize="off" aria-autocomplete="list" aria-owns="form_autocomplete_suggestions-1542902425322 form_autocomplete_selection-1542902425322">
If the value of form_autocomplete_suggestions-1542902425322 was static I would use .Document.getElementById("form_autocomplete_suggestions-1542902425322").Value = "Role: Student" however this seems to be a randomly generated numerical value.
I have had a look and it seems I cannot simply add a wildcard in such as .Document.getElementById("form_autocomplete_suggestions-*").Value = "Role: Student"
And as its randomly generated and such a long number it cannot loop through an array of values. so I am unsure on how to solve this issue.
You can use css attribute equals value selector syntax with the ^ operator to say starts with a certain substring. You could also use * instead, which means contains.
[id^='form_autocomplete_input-']
VBA:
ie.document.querySelector("[id^='form_autocomplete_input-']")
You might also use:
[placeholder='Search keyword or select filter']
Which would be:
ie.document.querySelector("[placeholder='Search keyword or select filter']")
As you indicate this needs to be selected you may need:
ie.document.querySelector("[id^='form_autocomplete_input-']").Selected = True
Reference:
CSS attribute selectors