最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

xpath - How to catch the value of an HTML text input named city in this code snippet? - Stack Overflow

programmeradmin7浏览0评论

enter image description here

enter image description here

HI want to build an automation that will extract the shipping address of a customer from the element that on the attached picture - and I need help - with figuring out how to extract the value of the city to make the automation. I tried to extract the CSS and the XPath selectors with Chrome extensions but the selectors that provided via Chrome extensions are not providing any results

For example - please advise how to get the CSS or XPATH selector of the "City" value from this piece of code:


<div class="control-group">
     <label for="city" class="control-label" data-i18n="[html]c706c0f0-16af-4c60-89de-0714aff0b08a">City</label>
     <div class="controls">
          <input type="text" placeholder="" class="m-wrap span12" name="city">
     </div>
 </div>

I watched tutorials on youtube , tried ask AI , and also many different variation of selectors but nothing work. Any help will be appreciated.

enter image description here

enter image description here

HI want to build an automation that will extract the shipping address of a customer from the element that on the attached picture - and I need help - with figuring out how to extract the value of the city to make the automation. I tried to extract the CSS and the XPath selectors with Chrome extensions but the selectors that provided via Chrome extensions are not providing any results

For example - please advise how to get the CSS or XPATH selector of the "City" value from this piece of code:


<div class="control-group">
     <label for="city" class="control-label" data-i18n="[html]c706c0f0-16af-4c60-89de-0714aff0b08a">City</label>
     <div class="controls">
          <input type="text" placeholder="" class="m-wrap span12" name="city">
     </div>
 </div>

I watched tutorials on youtube , tried ask AI , and also many different variation of selectors but nothing work. Any help will be appreciated.

Share Improve this question asked Mar 19 at 14:41 Pro4automationsPro4automations 12 bronze badges 1
  • 1 Code must be posted as plain text, not images. – LMC Commented Mar 19 at 14:45
Add a comment  | 

1 Answer 1

Reset to default 0

Using document.querySelector (Best Approach)

let cityValue = document.querySelector('input[name="city"]').value;
console.log(cityValue);

//Using getElementsByName

let cityInput = document.getElementsByName("city")[0]; 
console.log(cityInput.value);

//Using getElementsByClassName

let cityValue = document.getElementsByClassName("m-wrap span12")[0].value;
console.log(cityValue);

Edit

If your app accepts CSS selectors, use:

input[name="city"]

If your app accepts XPath, use:

//input[@name='city']

Both will select the city input field, and your automation tool should be able to fetch its value!

发布评论

评论列表(0)

  1. 暂无评论