I am trying to check different checkbox available but I am not able to get the id for the same.I tried xpath :
#browser.checkbox(:xpath => "//SPAN[#id='incentive_4000215652']").set
and
#browser.checkbox.span(:id => 'incentive_4000215652').set
The link to page is
https://secure.bestprice.rankingsandreviews.com/nc/configurator/301937
Click on Edit besides Exterior color and click Incentives tab.
Any help would be appreciated.Thanks!
Use this
browser.element(text: "2017 GM Conquest Cash").parent.preceding_sibling.span.click
Or use this
browser.element(xpath: "//*[normalize-space()='2017 GM Conquest Cash']/../preceding-sibling::td/span").click
If you change the text inside, then it click the corresponding checkbox.
Second one is bit faster than the first one, because WATIR doesn't go to form the xpath since xpath is directly available to you.
Full code follows here
browser.goto('https://secure.bestprice.rankingsandreviews.com/nc/configurator/307715')
browser.element(:id => 's2id_select_style').click
browser.element(xpath: ".//*[#id='select2-drop']/div/input").send_keys('Convertible LT 1LT', :tab)
browser.element(id: 'edit_color').click
browser.span(text: 'Incentives').click
browser.element(text: "2017 GM Conquest Cash").parent.preceding_sibling.span.click
Or
browser.element(xpath: "//*[normalize-space()='2017 GM Conquest Cash']/../preceding-sibling::td/span").click
Related
I am a little bit new to programming but python really made get into it. I am trying to create a programm that automatically checks for updates in a website. I've successfully implemented the neccessary code to call the page of enrollment but yet there is one element that cannot be located. Since I have to do it for multiple courses and iterate throught them there is no specific id, I've tried to find it by title but also this didn't work.
Is there a way you can locate the button with the title "enroll".
I've tried
driver.find_element_by_xpath("//a\[#title ='enroll']").click()
but this didn't work and I always get
NoSuchElement
error.
The XPATH for the button is simply: //*\[#id="id572"\]
Here is the part of the HTML code:
From the screenshot of HTML code you provided, the element is <button>, not <a>.
Try this xpath expression //button[#title='enroll']
This should do it if it's not in any iframes. Just grab the button whose title is enroll and click. Your css selector was an a tag and it might get id dynamically.
driver.find_element_by_css_selector("button[title ='enroll']").click()
I'm writing a VBA code to login into a webpage and load some information i have in an excel worksheet.
I'm new in Selenium. I already got the login part right, but now i need to click in an element and i keep getting errors.
I need to click in the Company 2 button.
This is what i've got so far:
bot.FindElementByXPath("//input[#value=""Company 1""]").Click
Outputs NoSuchElementError
bot.FindElementByXPath("//input[#value=""Company 2""]").Click
Outputs ElementNotVisible
I don't know what i'm doing wrong, i think that the first input being hidden has something to do. Hope anyone can help me.
Might help you to know you can also use ByCss in most circumstances, in which case you can use:
bot.FindElementByCss("input[value='Company 1']").Click
That is nice and short.
The CSS selector is input[value='Company 1']. This says find element with input tag having attribute value with value of 'Company 1'.
XPath might be incorrect. Please try the following syntax:
FindElementByXPath("//input[#value='Company 1']")
First of all, use CSS selectors whenever possible. They are much easier to handle.
Now if you are using CSS selectors try to find the second button using something like
input[value="Company 2"]
For more info on this selector, look at https://www.w3schools.com/cssref/sel_attribute_value.asp
You can use any xpath, in first look I found your xpath is incorrect, try this:
//input[#type='button'][#value='Company 2']
//input[#type='button'&& #value='Company 2']
//input[#role='button'][#value='Company 2']
You can also use findelements() to store are all buttons and using if else you can extract the company 2 button
As per the HTML you have shared to invoke click() on the desired elements you can use the following solution:
To click on the element with text as Company 1:
bot.FindElementByXPath("//input[#class='btn_empresa ui-button ui-widget ui-state-default ui-corner-all' and #value='Company 1']").Click
To click on the element with text as Company 2:
bot.FindElementByXPath("//input[#class='btn_empresa ui-button ui-widget ui-state-default ui-corner-all' and #value='Company 2']").Click
Have you tried right-clicking the HTML in inspect and going to Copy>Copy XPath? That might give you something different. Maybe the buttons are created from Javascript and so the WebDriver can't actually see them?
Or try
Company_1 = bot.find_element_by_xpath("//input[#value='Company 1']")
Company_1.click()
Company_2 = bot.find_element_by_xpath("//input[#value='Company 2']")
Company_2.click()
And change the syntax with the ' ' quotes like someone else mentioned.
I have been studying jQuery recently and wanted to try out some things on my own that the tutorial does not specify, I have searched online for it but can't find the answer. Basically I made a simple form text box and when the user focus' on the text box but doesn't type anything in and clicks somewhere else a message displays "Forgot to add text?" but i want to have an image pop up instead of just text, how would i do that?
enter image description here
$("input").blur(function(){
if( $(this).val()==""){
$(this).css('border','sold 1px red');
$('#box').text('Forgot to add text?');
ps: made a small yellow box in css and inside that box is where the message displays, thats why you see the "#box"
how about using CSS background-image?
if( $(this).val()==""){
$(this).css('border','sold 1px red');
$('#box').css('background-image', 'url(url_to_image.jpg)'):
$('#box').text('Forgot to add text?');
But don't forget sizing and positioning. ;)
Did not try it out, but it could work.
I used set to insert a value in a text field under a div.
Below is the approach that I've used without success. This is the only way I was able to identify the element. When I tried to identify text field by name was not recognized.
#browser.div(:evaluation, :id => "evaluation_form_attributes").text_field(:id => "evaluation_form_name")
#browser.set('Teacher Evaluation Form')
The following error was displayed:
undefined method `set' for #<Watir::IE:0x4dd9348>
This is the HTML:
div id="evaluation_form_attributes"
Evaluation name:
input id="evaluation_form_name" type="text" size="50" name="evaluation_form[name]" maxlength="30"
Try this:
browser.text_field(:id => "evaluation_form_name").set 'Teacher Evaluation Form'
Is there an iframe involved perhaps? if you know the thing is there, and you are sure of the ID, and watir cannot locate it, then usually it's because that part of the page is inside of a frame.
To work with elements that are inside of a frame, you must specify the frame, then the element
browser.frame(:how, what).element(:how, what).method etc.
see http://wiki.openqa.org/display/WTR/Frames for more info
To set a value for a text field you simply need to find it and set it. The setting part you already know (set), so you need to string together something that finds the text field.
if Zejiko's answer doesn't work because of "unable to locate element" then it's not the setting that's failing, it's finding the text field. Use Firebug (in Firefox) or some kind of DOM toolkit (Tools>Developer Tools or F12 in IE8) to find the text field and see what kind of attributes it has.
Ensure the id is really "evaluation_form_name". This is case sensitive and sensitive to leading/trailing spaces. You could try the following to make your search broader:
#browser.text_field(:id => /evaluation/).set 'Teacher Evaluation Form'
This uses a regular expression to identify the id. You can search by many things, not just :id, and you can use more than one. For example:
#browser.text_field(:id => /eval/, :index => 2)
finds the second text field whose id contains "eval".
What you can use to identify the text field can be found here: https://github.com/watir/watir/wiki/HTML-Elements-Supported-by-Watir
i need to display an extrafield (virtuemart standard attribute) on flypage over the product image.
I need it as a "customization print option" to display what user want to write over product!
I need the field under other extrafield (as it is normally), but let it appear over image only when user write on it! Is it possible?
Or is there some other solution for this?
Here's the example:
I'm using:
Joomla V 1.5.14
Virtuemart V1.1.6
code are welcome, i'm not so expert!
thank you
The first solution that comes to mind is to use Mootools (since VM already loads it) to update a blank div that you position over the top of the image. This is a built in function in Mootools.
http://mootools.net/docs/core/Element/Element#Element%3areplaces