I want to choose/select a particular date of a month and my screen displays multiple months on the screen (for example - JAN, FEB, MAR ).
Here is my tree structure:
div class="MeCalendarMonthDay MeCalendarWeekDay3"
style="width:14.285714285714286%;height:50px">
<span>14</span>
<input type="hidden" value="Wed Aug 14 2013">
</div>
I tried the below options ( I am using selenium test automation tool )
calender = driver.findElement(By.className("MeCalendarMonthNotSingle"));
date = calender.findElement(By.xpath("//div[#class='MeCalendarMonthName' and
contains(.='Aug 2013')]"));
date.findElement(By.xpath("//input[#value = 'Tue Aug 13 2013']")).click();
Also I tried
date.findElement(By.xpath("//input[#type='hidden' and value = 'Tue Aug 13
2013']")).click();
But, none of the above options are working for me. Can you please help me ?
The below option at times works.However, it fails to recognize the month as there are
multiple months displayed on the page.
date.findElement(By.xpath("//span[text()='13']")).click();`
Here you have some XPath solutions. Don't exactly know which element you want to be returned:
Selects on #class from <div> and #value from <input>. Returns the <input> element:
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay')]/input[contains(#value, 'Aug 14')]"));
Selects on #class from <div> and #value from <input>. Returns the <div> element:
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay') and input[contains(#value, 'Aug 14')]]"));
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay')][input[contains(#value, 'Aug 14')]]"));
Selects on #class from <div> and text() from <span> and #value from <input>. Returns the <input> element:
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay') and span = 14]/input[contains(#value, 'Aug 14')]"));
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay')][span = 14]/input[contains(#value, 'Aug 14')]"));
Selects on #class from <div> and text() from <span> and #value from <input>. Returns the <div> element:
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay') and input[contains(#value, 'Aug 14')] and span = 14]"));
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay')][span=14][input[contains(#value, 'Aug 14')]]"));
If you want the <span> element to be returned:
Selects on #class from <div> and #value from <input>. Returns the <span> element:
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay')][input[contains(#value, 'Aug 14')]]/span"));
calender.findElement(By.xpath("//div[contains(#class,'MeCalendarMonthDay') and input[contains(#value, 'Aug 14')]/span"));
Related
Only requirement: it needs to refer to the thread-navigation class, because that page has many other pagination elements
<section id="thread-navigation" class="group">
<div class="float-left">
<div class="pagination talign-mleft">
<span class="pages">Pages (6):</span>
<span class="pagination_current">1</span>
2
3
4
5
6
Next ยป //<--- this one
</div>
</div>
</section>
I was trying something like this:
r.xpath('//*[#class="thread-navigation" and contains (., "Next")]').get()
But it always returns None
Thank you
You are not referring to an #class attribute, but rather to an #id attribute with the value thread-navigation. So try this XPath-1.0 expression:
r.xpath('//a[ancestor::*/#id="thread-navigation" and contains (text(), "Next")]/#href').get()
Its result is
I want this text?page=2
This xpath:
'//section[#id="thread-navigation"]//a/#href'
I am writing a simple script to find and enter text into First name and Last name fields for a web page profile in firefox. I have navigated to the page and inspected the element, however I have tried everything i can think of the find the element but nothing seems to work. How can I find these fields using ruby, is there another way to inspect the field?
Both of these fields have field labels
First name inspect result
<div class="input__label">First Name</div>
<div class="input_row">
<div class="split_control">
<input class="input__input_wide" step="any" value="Bob">
Last name inspect result
<div class="input__label">Last Name</div>
<div class="input_row">
<div class="split_control">
<input class="input__input_wide" step="any" value="Smith">
You can try with following x-paths:
First Name element: //div[text()='First Name']/following-sibling::div/div/input
Last Name element: //div[text()='Last Name']/following-sibling::div/div/input
In code,
first_name = driver.find_element(:xpath, "//div[text()='First Name']/following-sibling::div/div/input")
first_name.send_keys "FName"
last_name = driver.find_element(:xpath, "//div[text()='Last Name']/following-sibling::div/div/input")
last_name.send_keys "LName"
Write the xpath like given below
driver.find_element(xpath: "//div[normalize-space()='First Name']/following::input").send_keys "FirstName"
For LastName
driver.find_element(xpath: "//div[normalize-space()='Last Name']/following::input").send_keys "LastName"
I have the following HTML snippet:
<input type="text" id="manufacturer" list="manufacturers" placeholder="Search by manufacturer name or supplier code" class="form-control form-control-2-3" value="" name="manufacturer">
<datalist id="manufacturers">
<select>
<div>
<option value="Jaguar">AA</option>
<div></div>
</div>
<div>
<option value="Audi">AB</option>
<div></div>
</div>
<div>
<option value="Mercedes">AC</option>
<div></div>
</div>
</select>
</datalist>
It's a dropdown menu and I want to select one of the options. No matter what I try with any find command or select function. I always get the same error:
Selenium::WebDriver::Error::ElementNotVisibleError: element not visible: Element is not currently visible and may not be manipulated
Does anyone have any suggestions on how to scope to those options and select one?
Thanks.
What you're trying to do isn't currently possible because it's not actually a dropdown select element. The <datalist> option elements are never actually visible on the page because the standard states "In the rendering, the datalist element represents nothing and it, along with its children, should be hidden." - https://html.spec.whatwg.org/dev/form-elements.html#the-datalist-element . Instead any <option> elements in the datalist are just used as autofill suggestions for the input element (but don't actually restrict the value a user can input in any way). Because of this and since the datalist user can just type anything they want into the input element you can set the input value like any other text input.
fill_in("manufacturer", with: 'Jaguar')
I'm trying to create an xpath to find an element which doesn't have any 'p', 'li', or 'span' preceding elements under a common parent. For example I have this structure:
<a>
<div>
<div/>
<div>
<div>
<div>
</p>
</div>
<img/>
</div>
<div>
<ci/>
</div>
</div>
</div>
</a>
The node I'm interested in is the <img> element. So far I have this xpath:
count(/a/div[1]/div[position() = last()]//img[(count(preceding::*[name() = 'p' or name() = 'li' or name() = 'span']) = 0)]) > 0
I don't care if any of the unwanted elements are under /a/div[1]/div[1]/ only under /a/div[1]/div[2]. With that said, preceding won't work because it'll look under /a/div[1]/div[1] which I don't care for. The 'p' element in the above example can be in any number of divs.
EDIT:
I added the div containing the element <ci/>.
I was able to get this to work using the following:
count(/a/div[1]/div[position() = last()]//img[(count(preceding::*[(name() = 'p' or name() = 'li' or name() = 'span']) and ancestor::div[parent::div[parent::a] and descendant::ci]]) = 0)]) > 0
Given following markup
<div>
<a>Username1</a>
</div>
<div>
<button>Unblock</button>
</div>
<div>
<a>Username2</a>
</div>
<div>
<button>Unblock</button>
</div>
<div>
<a>Username3</a>
</div>
<div>
<button>Unblock</button>
</div>
How do I select button element which is a cousin of a element with text Username2?
I can select the a element with //a[contains(., 'Username2')], so I thought that //a[contains(., 'Username2')]/following-sibling::/div/button would select the correct button, but that does not work. I think that it's not even valid XPATH.
You were close:
//a[contains(., 'Username2')]/../following-sibling::div[1]/button
To navigate to the cousin you first have to go to the parent (..) and then to its sibling.
Note that the following-sibling:: axis selects all following siblings, not only the first one. This means you must use [1] if you just want the first.
This would also work:
//a[. = 'Username2']/../following-sibling::div[1]/button
So would this:
//div[a = 'Username2']/following-sibling::div[1]/button