I have a form such as this:
I am trying to set the input field value to a postal code value "M3C1B4" and then I would like to click the button.
Although I can click the button I am unable to set the value of the input field.
I've tried the following code with no success:
driver.execute_script('arguments[0].value = "M3C1B4";', driver.find_element_by_xpath('//div[#class="shippingBox-update"]//input'))
driver.find_element_by_xpath('//div[#class="shippingBox-update"]//input').send_keys('M3C1B4')
Clicking the button works using this code:
driver.find_element_by_xpath('//div[#class="shippingBox-update"]//button').click()
You are using _ instead of - in "shippingBox_update". Should be
driver.find_element_by_xpath('//div[#class="shippingBox-update"]//input').send_keys('M3C1B4')
By the way, why don't you use the <input> class?
driver.find_element_by_class_name("PC_change_input").send_keys('M3C1B4')
driver.find_element_by_class_name("button-submit").click()
Sorry for the trouble. I got it to work. Apart from the error where I had _ instead of - that was pointed out by "guy", there was another problem.
The box was populated by a default value that had to be cleared first because the box only allowed for 6 values.
This did the trick:
driver.find_element_by_xpath('//div[#class="shippingBox-update"]//input').clear()
driver.find_element_by_xpath('//div[#class="shippingBox-update"]//input').send_keys('M3C1B6')
driver.find_element_by_xpath('//div[#class="shippingBox-update"]//button').click()
Related
So I am trying to use Protractor to test a non-angular application (using Mocha). I have this code:
var page = createAccountPage.create('/noname');
page.typeFirstNameInput('jane');
page.typeLastNameInput('doe');
page.typePasswordInput('password');
page.clickAgreedToTermsInput();
page.clickCreateAccountButton();
page.redirectToCreateProfilePage();
Note that the type*() are all pretty much the same:
createAccountPage.typeFirstNameInput = function(value) {
$(selector).sendKeys(value);
};
This basically opens the browsers and should fill in the form fills and then clicks a button that redirect the page. The issue that I am running into is that it fills out all the form inputs except the first name. If I do this:
var page = createAccountPage.create('/noname');
page.typeFirstNameInput('jane');
page.typeFirstNameInput('jane');
page.typeLastNameInput('doe');
page.typePasswordInput('password');
page.clickAgreedToTermsInput();
page.clickCreateAccountButton();
page.redirectToCreateProfilePage();
Then it does fill out the first name however I get the error:
StaleElementReferenceError: Element is no longer attached to the DOM
The only reason I can see this happening is that the form is fill out correctly now and clicking the button redirects the pages and for whatever reason, the first page.typeFirstNameInput('jane'); is being executed last (which would also explain when when I have it there once, the first name is filled out).
Is there any reason why the first action page.typeFirstNameInput('jane'); would be executed last?
In a dialog box I have a combo box and a text field. I would like to make so that if one particular value in the combo box is selected, the text field would be disabled (or hidden), and if another value is selected, the text field would be enabled.
I have:
self.myCombo = wx.ComboBox(parent=self, choices=['value1', 'value2'], style = wx.CB_READONLY)
self.myCombo.Bind(wx.EVT_COMBOBOX, self.onChange)
# ...
def onChange(self, ev):
self.myTextField.Enable(False) if self.myCombo.GetValue() != "value1" else self.myTextField.Enable(True)
And this does work like a charm, the text field gets enabled and disabled.
However, I would like to have the text field enabled or disabled depending on the initial value of the combo box, meaning the value gotten from a config file and selected when the dialog box is open.
I've tried the same:
self.myTextField = wx.TextCtrl(parent=self)
self.myTextField.Enable(False) if self.myCombo.GetValue() != "value1" else self.myTextField.Enable(True)
but this doesn't work. I've tried GetSelection also, but when logging this, both GetValue and GetSelection return -1.
The combobox probably isn't fully initialized yet when you try to query it. If you want to disable it when it loads, you don't have to check its value. Just disable it. But for what you want to do, I would recommend using wxPython's wx.CallAfter() method.
Something like the following should suffice:
def __init__(self):
# initialize various variables
wx.CallAfter(self.check_combobox, args)
def check_combobox(self, args):
self.myTextField.Enable(False) if self.myCombo.GetValue() != "value1" else self.myTextField.Enable(True)
I have a custom product list page and i´m using the following code to show the pagenumbering and filters:
$pager = $this->getLayout()->createBlock('page/html_pager');
echo $this->getLayout()->createBlock('catalog/product_list_toolbar')->setChild('product_list_toolbar_pager', $pager)->setCollection($products)->toHtml();
If i'm changing the mode from grid to list view nothing happens.
How can i get the active mode (grid or list).
Magento normaly uses $this->getMode() but this one doesnt work.
I have fixed it with the following code:
$mode = $this->getLayout()->createBlock('catalog/product_list_toolbar')->setChild('product_list_toolbar_pager', $pager)->getCurrentMode();
Another solution,
if(Mage::getSingleton('catalog/session')->getDisplayMode())
{
$productListMode=Mage::getSingleton('catalog/session')->getDisplayMode();
}
I am developing my application in Sencha touch. In that I have a list and Picker and I want to update the list data dynamically when selecting the picker i.e., I want to add data to list dynamically when tap on 'Done' button of Picker. I used some logic for this but this doesn't update the list content.
listeners: {
change: function(picker,value) {
textValue = picker.getValue()['name'];
var me = this,
nameList = this.down('#namesList');
nameList.add({fullname:textValue}) ;
}
}
When I update like this, it throws me the error that 'Uncaught TypeError: Cannot call method 'add' of null' eventhough 'namesList' is already defined. Please show me the way to solve this problem.
I would add a record to the data/store of the list, and then capture the list and refresh.
The issue there is that nameList isnt actually the list component.
Try adding for example an id to the list, and then in the picker change listener:
Ext.getCmp('mylist-id').refresh()
Hope it helps.
In Sitecore I have created a custom field (via this recipe: http://sdn.sitecore.net/Articles/API/Creating%20a%20Composite%20Custom%20Field/Adding%20a%20Custom%20Field%20to%20Sitecore%20Client.aspx)
The field is for use in the content editor.
The custom field has a menuitem attached (the little textbutton rendered just above the field)
The custom field work as expected and the menuitem hooks into code in the custom field class as it should. However, the logic I need to implement for the menuitem requires that I get a reference to the item that is currently being edited by the user in the content editor.
However, to my surprise this doesn't work:
Sitecore.Context.Item
This does not give me the item that the user is currently editing, but instead the "content editor" item, which is always the same.
I would think there would simply be a property of some object in the API, but I can't find it.
If you are following this article then you will have defined a property on your control..
public string ItemID { get; set;}
.. this will be populated with the ID for the item you are editing. You should be able resolve the Item object from this ID using something like:
Sitecore.Data.Database.GetDatabase("master").GetItem(ItemID)
.. if you are just looking just for the value of the field you are editing you can use the base.Value field.
The best place to ask this would be on the developer forum, you should get a good response on there.
Though, taking a look through the Sitecore code, it looks like this might be what you want. Try reading it from the ViewState:
public string ItemID
{
get
{
return base.GetViewStateString("ItemID");
}
set
{
Assert.ArgumentNotNullOrEmpty(value, "value");
base.SetViewStateString("ItemID", value);
}
}
Stephen Pope is right, though there are more properties that you can 'automagiacally' retrieve from Sitecore. Some properties, just like ItemID are put on the field via reflection. There's also the ItemVersion and Source that can be useful for your custom controls.
If you're intereseted, take a peek inside the class Sitecore.Shell.Applications.ContentEditor.EditorFormatter, and especially its method SetProperties:
ReflectionUtil.SetProperty(editor, "ItemID", field.ItemField.Item.ID.ToString());
ReflectionUtil.SetProperty(editor, "ItemVersion", field.ItemField.Item.Version.ToString());