1

I´m new in the Python Community, so I'm struggling each line of the Script I'm developing. I will appreciate if any of you can help me with this 'cos I´ve been hours trying to solve it and I can´t.

I want to copy these variables POSIN (from Film), HORROR (from Topic).HTML SOURCE CODE:

<div id="text"></div>
<h2 class="form-sign">
<b>DATA</b>
</h2>
<br></br>
<div>
<p>
<b>Film: </b>
POSIN
</p>
<p>
<b>Topic: </b>
HORROR
</p>
</div>
<input name="Description" value="1" type="hidden">

I'm using Selenium with python, I´m trying:

Film = driver.find_element_by_name("Film")

but doesn´t works:

NoSuchElementException: Unable to locate element: {"method":"name","selector":"Film"}

2 Answers 2

1

"Film" is not name, its text. Name attribute will look like <b name="Film"> Film: </b>.

Also, its Film:, spaces and unique characters are important when searching. Try this

film = driver.find_element_by_xpath(".//b[contains(text(), 'Film')]")

And to get the text

filmText = film.text
Sign up to request clarification or add additional context in comments.

Comments

0

Film is not a name. To learn about more that how to locate element refer below link :-

http://selenium-python.readthedocs.org/locating-elements.html

For Film use below xpath

//p[contains(., 'Film')][1]

For Topic use below xpath

//p[contains(., 'Topic:')][1]

For Film use below code..

  movieText =   driver.find_element_by_xpath("//p[contains(., 'Film')][1]")

movieText is element you have found

For Topic use below code

  movieTopic =  driver.find_element_by_xpath("//p[contains(., 'Topic:')][1]")

movieTopic is element you have found

Now to extract text from above element by using below code:-

TextOFFilm = movieText.text

TextOFTopix = movieTopic.text

text is a built-in function which extract text from web element.

Hope it will help you :)

2 Comments

A million of thanks, thanks to you I can continue. I've been hours and hours and finally I can continue. Thanks!!!
Welcome @Johnny007 ... I am happy as your problem is resolved :)

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.