0

I want to input "apple" instead of "hello" using Selenium in Python.

<span><div class="top1"><div class="top2"><label class="top3">
<label class="check"><input class="word" type="text" value="hello"></label>

How to do it?

Thank you very much.

9
  • How did you try? Commented Feb 14, 2018 at 8:15
  • I tried "driver.find_element_by_class_name('word')" but failed. Commented Feb 14, 2018 at 8:21
  • I will use send_keys() but I need to locate it first. Commented Feb 14, 2018 at 8:27
  • So the problem is not in sending keys but in locating element? You should update your question with correct description + your code + exception log Commented Feb 14, 2018 at 8:36
  • I certainly want to input text. It's just "driver.find_element_by_xpath('....').send_keys('apple')". But I don't know the first part. Commented Feb 14, 2018 at 8:41

2 Answers 2

4

As per the HTML you have provided, to send the text apple within the <input> element you can use the following code block :

driver.find_element_by_xpath("//label[@class='check']/input[@class='word' and @type='text' and @value='hello']").click()
driver.find_element_by_xpath("//label[@class='check']/input[@class='word' and @type='text' and @value='hello']").clear()
driver.find_element_by_xpath("//label[@class='check']/input[@class='word' and @type='text' and @value='hello']").send_keys("apple")
Sign up to request clarification or add additional context in comments.

Comments

-1

Before asking elementary questions like this, please read documentation for tools which you are using. You can find documentation via Google.

About your task. First, you need find your input in source code, than clean value and input a new one.

your_input = driver.find_element_by_xpath('xpath to your input')
your_input.clear()
your_input.send_keys('your new text')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.