Reputation: 1
Original HTML Code
<form id="commentUpdateForm" method="post" data-commentid="">
<fieldset>
<input type="hidden" name="point" value="">
<div class="grade_star">
<span class="ico_star star_rate">
<span class="ico_star inner_star" style="width: 0%;"></span>
</span>
<em class="num_rate">0<span class="txt_g">/5</span></em>
<span class="txt_word">Please rate it</span>
</div>
<div class="write_review">
<label for="tfReview" class="lab_review">What did you like about this place?</label>
<textarea name="contents" id="tfReview2" class="tf_review"></textarea>
</div>
</fieldset>
</form>
If I click 3 out of 5 points, the HTML code will be changed like this.
<form id="commentUpdateForm" method="post" data-commentid="">
<fieldset>
*<input type="hidden" name="point" value="3">*
<div class="grade_star">
<span class="ico_star star_rate">
*<span class="ico_star inner_star" style="width: 60%;"></span>*
</span>
<em class="num_rate">0<span class="txt_g">/5</span></em>
<span class="txt_word">Normal</span>
</div>
<div class="write_review">
<label for="tfReview" class="lab_review">What did you like about this place?</label>
<textarea name="contents" id="tfReview2" class="tf_review"></textarea>
</div>
</fieldset>
</form>
So what I want to do is to make it possible to modify it with Python Selenium code for points, but I don't know.
Upvotes: 0
Views: 49
Reputation: 3244
You can locate the element with selenium webdriver and modify its value attribute like that:
element = driver.find_element_by_xpath('//form[@id="commentUpdateForm"]//input[name="point"]')
element.setAttribute("value", "3")
Upvotes: 1