Trying to click in the message box using selenium webdriver - python

Trying to click on the message box for every new message window that pops up. However it seems as if the id changes every time. How do I get this to work for everytime a new message box pops up.
Here is what I tried:
passMessage = browser.find_element_by_css_selector('ember-text-area msg-messaging-form__message ember-view')
For example:
<textarea name="message" spellcheck="true" required="" placeholder="Write a message or attach a file" id="a11y-ember8470" class="ember-text-area msg-messaging-form__message ember-view"></textarea>
<textarea name="message" spellcheck="true" required="" placeholder="Write a message or attach a file" id="a11y-ember8492" class="ember-text-area msg-messaging-form__message ember-view"></textarea>

It is a css class name, so you need a dot:
passMessage = browser.find_element_by_css_selector('.ember-text-area.msg-messaging-form__message.ember-view');
http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.action_chains

Related

How to update AngularJs input tag value using Selenium with Python?

The target input element :
input ng-required="$ctrl.isRequired" name="" moment-picker="$ctrl.selectedFormattedDate" ng-model="$ctrl.selectedMoment" value="Fri Mar 27 2020 00:00:00 GMT+0530" ng-disabled="$ctrl.disabled" class="mw-date-picker mw-date-picker-dropdown ng-pristine ng-valid moment-picker-input md-input ng-not-empty ng-valid-required ng-valid-min-date ng-valid-max-date ng-touched" format="L" locale="en" min-view="year" max-view="month" start-view="month" timezone="$ctrl.timezone" today="$ctrl.isTodayHighlighted" change="$ctrl.handleDateChange(newValue, oldValue)" min-date="$ctrl.minDate" max-date="$ctrl.maxDate" tabindex="0" id="input_198" required="required" aria-invalid="false" style="">
I tried changing the attribute "value" using Python code:
driver.execute_script("arguments[0].value = '03/10/2019';", element)
This commands updates the value in the front end but the changes are not saved after clicking OK(there is no issue with OK button click code). I also tried changing "moment-picker" but it did not help either.
Can someone please help me with some way out using Python?

Input text field value behavior after Get request

I have this form
<form class="form-inline" type="get" action=".">
<input id="excel_input" class="form-control" type="text" name="excel_input" value="0">
<input class="btn" type="submit" name="excelbutton" value="excelbuttonclicked"
onclick='document.getElementById("excel_input").value = "1";'><i class="ion ion-search"></i></input>
</form>
I want to get the value "1" when the excelbutton clicked in the Get request in order to export an excel file. I want to use the Get request because in this point I have a ready query set , the query set user sees on the screen.
I use the commands
request.GET.get('excel_input', None)
if excel_string not in ['0', None]:
testxlsxwriter(d_list)
to get the value of the input field and export the excel file. The problem is that I get the value "1" from the input field on button click , but then I always get the value "1" on get requests( refresh , next page etc.
I see the value "0" on screen on refresh but I get the value "1" on my view
I also tried javascript with no luck
window.onload = function(){
document.getElementById("excel_input").value = "0";
}
Can someone help me please to understand how get request works with this input element?
Thanks a lot
Kostas

Radio button does not get clicked in Selenium / Python

Folks, this is driving me crazy. I have snippets like the following
<label class="" for="M37_Q_POSWECHSEL_BETT_B1">
<input id="M37_Q_POSWECHSEL_BETT_B1" name="M37_Q_POSWECHSEL_BETT" value="B1" aria-describedby="M37_Q_POSWECHSEL_BETT_error_0" aria-invalid="true" data-clipboard="M37_Q_POSWECHSEL_BETT#B1" type="radio">
0
</label>
Here, I'd like to select the radio buttons and select them with the following code:
radios = driver.find_elements_by_xpath("//input[starts-with(#id, 'M37_Q_')][#value='B1']")
for radio in radios:
# just check the id
print(radio.get_attribute('id'))
radio.click()
It correctly selects the elements in question. However, it does not get selected nor does it yield any obvious errors. Can we use .click() to select radio buttons here? Is this some kind of handler problem?
Try this,
driver.execute_script("arguments[0].checked = true;",element)
You can also try by sending ENTER Key to the element.
Try using following Css selector:
Actions action = new Actions(drive);
action.moveToElement(drive.findElement( By.cssSelector("label > input[id^='M37_Q_']"))).build().perform();
drive.findElement( By.cssSelector("label > input[id^='M37_Q_']")).click();

Selecting an unnamed text field in a mechanize form (python)

So i'm making a program to batch convert street addresses to gps co-ordinates using mechanize and python. this is my first time using mechanize. I can select the form ("form2') on the page. however the text box in the form has no name. how do i select the textbox so that mechanize can enter my text? I've tried selecting it by its id. but that does not work.
br.select_form("Form2") #works as far as i know
br.form["search"] = ["1 lakewood drive, christchurch"] #this is the field that i cannot select
and here is the source code from the website.
<form name="Form2" >
or Type an <b>Address</b>
<input id="search" size="40" type="text" value="" >
<input type="button" onClick="EnteredAddress();" value="Enter" />
</form>
any help would be much appreciated.
form.find_control(id="search") ?
FWIW I solved this by using the above answer by lazy1 except that I was trying to assign a value after using the find_control method. That didn't work of course because of assignment, I looked deeper into the method and found setattr() and that worked great for assigning a value to to the field.
will not work
br.form.find_control(id="field id here") = "new value here"
will work
br.form.find_control(id="field id here").__setattr__("value", "new value here")

Use getControl to control objects other than the name variable

I am using the Zope testbrowser which has been recommended in my last question. The problem that I am facing is that I can use the getControl function to control different objects like: password, username etc.
I am trying to submit the page to get to the next page but the submit button has no 'name' variable, just an 'id' variable. 'Submit' is written as follows:
<input type="submit" id="lgn_button" class="button" tabindex="3" accesskey="s" />
and the other objects are written as:
<input type="password" class="button" name="password" id="password" size="24" maxlength="20" accesskey="p" tabindex="2" value=""/></td>
I have no access to change this. The python zope code I am using to gain control of the 'password' object is:
browser.getControl(name='password')
The submit button doesn't have 'name' so I have written:
browser.getControl(id='lgn_button')
This prints out the error that 'id' is invalid:
TypeError: getControl() got an unexpected keyword argument 'id'
Is there any way to gain control of one of the other values in 'submit'.
Thanks for any help.
I assume that, for one reason or another, you can't add a 'name' attribute to your tag, but if it's only a 'name' that you can't add, you can explicitly set a 'value=Submit' (instead of relying on the default one, which is Submit) and then use browser.getControl('Submit')
Failing that, you can do something along the lines of
for form in browser.mech_browser.forms():
for control in form.controls:
if control.id == 'lgn_button':
return control
You might even want to extend Browser.getControl() with that and contribute it back to zope.testbrowser. ;)

Categories

Resources