All checkboxes are checked first, after that I try to uncheck all besides "Киберспорт"
I don't understand why Selenium can't click some checkboxes..
I use this script
checkboxes = subpage.find_elements_by_xpath(".//div[contains(#class, 'col-xs-6 col-md-3 order-item')]") # list of all checkboxes
for i, chckbx in enumerate(checkboxes):
if chckbx.get_attribute("data-order") != "Киберспорт":
print(f"{chckbx.text}") # I get all names of checkboxes besides "Киберспорт"
chckbx.click()
However, Selenium clicks not all checkboxes
Result is shown on the picture
First 2 checkboxes in HTML:
<div class="col-xs-6 col-md-3 order-item" data-order="Авст. футбол">
<div class="checkbox">
<input checked="checked" name="sports[]" value="20" id="sports_20" type="checkbox">
<label for="sports_20">
<span class="custom_checkbox"></span>
<p>Авст. футбол</p>
</label>
</div>
</div>
<div class="col-xs-6 col-md-3 order-item" data-order="Гэл.спорт">
<div class="checkbox">
<input checked="checked" name="sports[]" value="23" id="sports_23" type="checkbox">
<label for="sports_23">
<span class="custom_checkbox"></span>
<p>Гэл.спорт</p>
</label>
</div>
</div>
The checkboxes has an id. It may be easier to search by the id. subpage.find_element_by_id('sports_20')
Related
Here when country name is given in the text field display all the states in the dropdown list
Here is my html code
<div class="control-group">
<label class="control-label pull-left" for="coubtry">Sales order</label>
<div class="controls">
<input name="country_name" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label pull-left" for="capacity">Items</label>
<div class="controls">
<select name="states">
<option value="">-----</option>
( How to display the states in dropdown based on country given above??)
</select>
</div>
</div>
Here country is given in text and i need the states in dropdown list
I am using htmx and want my code to be able to retrieve the value of a set item in a radio group. Here is the htmx that I am trying to use:
<div id="js-scale">
<div>
<input type=radio name="Js" id="JsStrong"></input>
<label for="JsStrong">Agree</label>
</div>
<div>
<input type=radio name="Js" id="JsNeutral"></input>
<label for="JsNetutral">Neutral</label>
</div>
<div>
<input type=radio name="Js" id="JsPos"></input>
<label for="JsPos">Disagree</label>
</div>
<div id="control-block">
<button hx-post={{'/session/'+session+'/tweet/'+tweet+'/Skip'}} hx-trigger="click" hx-swap="innerHTML" hx-target="#session" type="button">Skip</button>
<button hx-post={{'/session/'+session+'/tweet/'+tweet+'/js_submit'}} hx-trigger="click" hx-swap="innerHTML" hx-target="#session" type="button" hx-include="[name='Js']">Submit</button>
</div>
</div>
When I press submit, and in the python use requests.get_data(), it returns Js=on, irrespective of which radio button has been selected.
How do I set this up to be able to determine which of the radio buttons has been selected?
I found that by explicitly setting the value for the button, it works fine. The correct snippet is:
<div id="js-scale">
<div>
<input type=radio name="Js" id="JsStrong value="JsStrong"></input>
<label for="JsStrong">Agree</label>
</div>
<div>
<input type=radio name="Js" id="JsNeutral" value="JsNeutral"></input>
<label for="JsNetutral">Neutral</label>
</div>
<div>
<input type=radio name="Js" id="JsPos" value="JsPos"></input>
<label for="JsPos">Disagree</label>
</div>
<div id="control-block">
<button hx-post={{'/session/'+session+'/tweet/'+tweet+'/Skip'}} hx-trigger="click" hx-swap="innerHTML" hx-target="#session" type="button">Skip</button>
<button hx-post={{'/session/'+session+'/tweet/'+tweet+'/js_submit'}} hx-trigger="click" hx-swap="innerHTML" hx-target="#session" type="button" hx-include="[name='Js']">Submit</button>
</div>
</div>
This is because of how HTML works, from the MDN 'input type=radio' page:
If you omit the value attribute in the HTML, the submitted form data assigns the value on to the group. In this scenario, if the user clicked on the "Phone" option and submitted the form, the resulting form data would be contact=on, which isn't helpful. So don't forget to set your value attributes!
I am trying to change the input field value in a form input using Selenium and Python, but unable to do so.
See time picker
I want to be able to perform .sendKeys() for each one (Hour, Minutes, Seconds, AM/PM). My code is the following:
end_time_input = driver.find_element_by_xpath('/html/body/div[4]/div[4]/div[2]/form/ol/li[2]/div/div/div[2]/div[2]/input')
end_mins_input = driver.find_element_by_css_selector('#ldb\:filter\:list\:1 > div > div > div.mins > div.mi_tx > input')
end_seconds_input = driver.find_element_by_xpath('//*[#id="ldb:filter:list:1"]/div/div/div[4]/div[2]/input')
end_meridian_input = driver.find_element_by_xpath('/html/body/div[4]/div[4]/div[2]/form/ol/li[2]/div/div/div[5]/div[2]/input')
time_input.send_keys("10")
end_mins_input.send_keys("30")
end_seconds_input.send_keys("30")
end_meridian_input.send_keys("AM")
However, this is not working.
I also tried changing the value from the main input --> input id="ldb:filter:list:1:timeInput"
> <div class="time_pick" style="display: inline-block;width: 140px">
<input id="ldb:filter:list:1:timeInput" class="axw-wdb-time ldb-input" name="ldb:filter:list:1:timeInput"
value="5:24:25 PM" placeholder="12:00:00 AM" aria-label="Time input End DateTime" data-timepicki-tim="10"
data-timepicki-mini="24" data-timepicki-sec="25" data-timepicki-meri="PM" style="opacity: 1;">
<div class="timepicker_wrap " style="display: none; top: 20px; left: 0px;"><div class="arrow_top">
</div>
<div class="time" id="time_column"><div class="prev action-next">
</div>
<div class="ti_tx"><input type="text" class="timepicki-input">
</div>
<div class="next action-prev">
</div>
</div>
<div class="mins">
<div class="prev action-next">
</div>
<div class="mi_tx">
<input type="text" class="timepicki-input">
</div>
<div class="next action-prev">
</div>
</div><div class="seconds">
<div class="prev action-next">
</div>
<div class="sec_tx">
<input type="text" class="timepicki-input">
</div>
<div class="next action-prev">
</div>
</div>
<div class="meridian" id="meridian_column">
<div class="prev action-next">
</div>
<div class="mer_tx">
<input type="text" class="timepicki-input" readonly="">
</div>
<div class="next action-prev">
</div>
</div>
</div>
</div>
Is this indeed a webased application? or application based?
With web based, does the element expose another dropdown or typeahead container with different xpath?
If application, elements should be made discoverable in code...
I'm new to selenium. In a website When I click on the navigation menu from the browser it opens up. But I couldn't open it with selenium webdriver.
Here is the source HTML Sample:
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse np" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown dropdown-1">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="icon-filter"></span>
Quick Filters
</a>
<ul class="dropdown-menu">
<li class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
<label class="nmt">
Category
</label>
<input type="hidden" id="hidJobCategory" value="-1" />
<div class="row">
<div class="col-md-12">
<div class="radio">
<label for="CategoryType1">
<input type="radio" checked name="CategoryType" id="CategoryType1" value="F" onclick="loadCatgory(this.value)"><!--loadCatgory(this.value)-->
Functional Category
</label>
<label for="CategoryType2">
<input type="radio" name="CategoryType" id="CategoryType2" value="B" onclick="loadCatgory(this.value)" ><!--loadCatgory(this.value)-->
Special Skilled Category
</label>
</div>
</div>
</div>
I tried this:
foo = driver.find_element_by_xpath('//*[#id="bs-example-navbar-collapse-1"]/ul/li[1]/a')
foo.click()
It didn't work. It redirects to another page.
Since it is a hyperlink you can also try:
driver. find_element_by_link_text('Quick Filters').click();
Not sure if you need to hover over the hyperlink before you click on it. If yes, then probably you will have to hover over it before clicking using the WebDriver Actions class.
I am trying to write python code which does the following:
1) Logs into OKCupid
2) Goes to a users questions page
3) Answers an unanswered question.
I am using RoboBrowser to do this. I can do steps 1), 2) and I can get the form of the question I want to submit, but once I submit (using RoboBrowser's submit) it doesn't seem to go through to OKCupid (in that the question isn't registered as answered on my profile).
Here is the code I have. Note the My_RoboBrowser just allows me to pass False to RoboBrowser.open for the verify argument.
class My_RoboBrowser(RoboBrowser):
def __init__(self, auth=None, parser=None, headers=None, user_agent=None, history=True):
RoboBrowser.__init__(self, parser=None, user_agent=None, history=True)
def Open(self, vURL, vVerify=True):
response = self.session.get(vURL, verify=vVerify)
self._update_state(response)
browser = My_RoboBrowser()
urlL = 'https://okcupid.com/login'
browser.open(url)
form = browser.get_form(id='loginbox_form')
form['username'] = 'Username'
form['password'] = 'Password'
browser.submit_form(form)
urlQ = 'https://www.okcupid.com/profile/USER/questions?low=1'
browser.open(urlQ)
Question_Tag = browser.find_all(class_="not_answered")[0]
ID = Question_Tag.get('data-qid')
#Get the form to fill out
Form = browser.get_form(id='answer_'+str(ID))
Form['my_answer'].value = '1'
Form['their_answer'].value = ['1']
Form['importance'].value = '1'
browser.submit_form(Form)
Also if it is helpful when I look at the form object Form in an IPython notebook it says:
<RoboForm my_answer=, their_answer=[], importance=>
before the submit and
<RoboForm my_answer=1, their_answer=['1'], importance=1>
after.
Finally, if it is helpful, the following is the code for one of the forms I am trying to answer (which was gotten by inspecting the element)
<form id="answer_179268" name="answer_179268" class="answer_area okform initialized">
<div class="container my_answer">
<input id="my_answer_1_179268" name="my_answer" value="1" false="" type="radio">
<label class="radio" for="my_answer_1_179268">
<span class="icon"></span>
Yes
</label>
<input id="my_answer_2_179268" name="my_answer" value="2" false="" type="radio"></input>
<label class="radio" for="my_answer_2_179268">
<span class="icon"></span>
No
</label>
</div>
<div class="container acceptable_answers">
<div class="title">
<p>Answer(s) you’ll accept</p>
</div>
<label class="checkbox acceptable_answer" for="their_answer_1_179268">
<input id="their_answer_1_179268" class="acceptable_answer" name="their_answer" value="1" false="" type="checkbox"></input>
<span class="icon"></span>
Yes
</label>
<label class="checkbox acceptable_answer" for="their_answer_2_179268">
<input id="their_answer_2_179268" class="acceptable_answer" name="their_answer" value="2" false="" type="checkbox"></input?
<span class="icon"></span>
No
</label>
<label class="checkbox irrelevant" for="their_answer_any_179268">
<input id="their_answer_any_179268" class="irrelevant" name="their_answer" value="irrelevant" type="checkbox"></input>
<span class="icon"></span>
Any of the above
</label>
</div>
<div class="container importance">
<div class="title">
<p>Importance</p>
</div>
<div class="importance_radios">
<input id="importance_179268_5" name="importance" value="5" false="" type="radio"></input>
<label class="importance_5 radio" for="importance_179268_5" data-count="5">
<span class="icon"></span>
<div class="bar"></div>
<span class="label"></span>
</label>
<input id="importance_179268_4" name="importance" value="4" false="" type="radio"></input>
<label class="importance_4 radio" for="importance_179268_4" data-count="4">
<span class="icon"></span>
<div class="bar"></div>
<span class="label">A little</span>
</label>
<input id="importance_179268_3" name="importance" value="3" false="" type="radio"></input>
<label class="importance_3 radio" for="importance_179268_3" data-count="3">
<span class="icon"></span>
<div class="bar"></div>
<span class="label">Somewhat</span>
</label>
<input id="importance_179268_2" name="importance" value="2" false="" type="radio"> </input>
<label class="importance_2 radio" for="importance_179268_2" data-count="2">
<span class="icon"></span>
<div class="bar"></div>
<span class="label"></span>
</label>
<input id="importance_179268_1" name="importance" value="1" false="" type="radio"> </input>
<label class="importance_1 radio" for="importance_179268_1" data-count="1">
<span class="icon"></span>
<div class="bar"></div>
<span class="label">Very</span>
</label>
</div>
<div class="irrelevant_message">
<span class="irrelevant_text">Irrelevant</span>
<span class="message_text">(Because you’ll accept any answer, this question is marked irrelevant)</span>
</div>
</div>
<div id="explanation_container_179268" class="container explanation">
<div id="answer_179268_explanationContainer" class="inputcontainer textarea noresize empty">
<textarea id="answer_179268_explanation" class="noresize" placeholder="Explain your answer (optional)" false=""></textarea>
<span class="message empty" style="height: 0"></span>
<div class="icon"></div>
</div>
</div>
<button id="submit_btn_179268" class="submit_btn flatbutton disabled small">Answer</button>
<button id="cancel_btn_179268" class="cancel_btn flatbutton silver small">Cancel</button>
<a class="skip_btn inner" href="javascript:void(0)" draggable="false">Skip question</a>
<div id="public_container_179268" class="answer_privately">
<label class="checkbox" for="private_179268">
<input id="private_179268" false="" type="checkbox"></input>
<span class="icon"></span>
<span class="text">Answer privately</span>
</label>
</div>
</form>
I've seen several cases where someone couldn't submit b/c the site used Javascript to submit forms. In other words, they could use Robobrowser or Mechanize to log in and fill out a form, but the form itself could not be submitted -- as submission relied on JS. That may be your problem here. If that's the case, you should try using Selenium.
You can likely verify whether JS is being used to submit in your browser's inspector. <ctrl + shift + i / network / *clear* inspector's network panel before clicking submit / click submit / check type for your Post>
I think that's how I verified, but others here would know better than me. Good luck!
You should take a look at https://github.com/IvanMalison/okcupyd. It will let you do this without using a browser.