I am trying to get xpath by index and i am not making an progress. protractor says "that the element has more than one element is found for locator choosing the 1st one". however I want to make sure that the 1st one is selected intentionally screen shot below:
My code: that is not working:
I tried the following site nothing works:
https://devhints.io/xpath
xpath get element by index
Any help would be appreciated.
var payroll = element.all(by.xpath('//*[text()="Payroll"]')).first();
Related
I am trying to iterate though pages of search results on this website. Here is a snippet of the HTML code they have for the paging section:
Paging HTML:
Link that I want to use to go to the next page:
Next >>
I was trying to do:
next_page_link = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//a[#href='/Catalogue/search?Query=face%20mask&QueryType=All&HideMaskedProducts=False&WasCorrected=False&Page=2&PageSize=10&TotalRecordCount=932&SortDescending=False&CoreListRequest=BrowseAll'")))
next_page_link.click()
but it doesn't seem to work. When I print out next_page_link, it does return an element, so I think the code itself if alright. Is it something wrong with the link? Can I use it the way I am trying to or is there any other way I can iterate thought the result pages?
Thank you!
Your XPATH is probably causing the issue here, so the click is not going to the correct element.
Try something like this
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//a/text()[contains(.,"Next")]/parent::*'))).click()
If you want to assign it to the variable and the call the click you can also do it:
next_page_link = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//a/text()[contains(.,"Next")]/parent::*')))
next_page_link.click()
can someone, please, help, in following case:
Found element with following css selector (there is a list of charts, where only one chart has mark with "Current Day" text on top of it).
'div[id*="view-panel"] div.bar_chart g.bar_chart__now > text'
Based on that element, want to find another element (which is on found chart - its bottom), which displays name of the day (i.e "Friday"). Tried with following code:
cy.get('div[id*="view-panel"] div.bar_chart g.bar_chart__now > text').as('currentDay');
cy.get('#ccurrentDay').find('..').find('..').find('g.bar_chart__xaxis text');
Whole css selector for second element (for second code line above), looks:
'div[id*="view-panel"] div.bar_chart g.bar_chart__xaxis text'
What I tried to achieve is after first found element, go two steps back and find day name of chart bottom, but what I only get is an error:
CypressError: Timed out retrying: Expected to find element: ‘…’, but never found it.
What I am doing incorrect in above attempt to concatenate finding element? Thank you in advance
You should use Within command
cy.get('div[id*="view-panel"] div.bar_chart g.bar_chart__now > text')
.within(()=>{
cy.get('g.bar_chart__xaxis text')
})
I am trying to loop through a series of pages (javascript) from the following webpage:
http://nh.mypublicnotices.com/PublicNotice.asp?Page=SEARCHRESULTS
I found all of the elements that I need to loop through, but I am unable to click on it. What would be the best way to loop through these javascript elements:
from selenium.webdriver.support.select import Select
next_page=driver.find_elements_by_xpath('//[#id="PublicNoticeContent"]/table[2]/tbody/tr/td/table[2]/tbody/tr[6]/td/table/tbody/tr/td/table/tbody/tr[1]/td/a')
for i in next_page:
link=i.get_attribute("href")
Select(link)
Select.click()
You need to repeat your materials on Select and working with a class.
link=i.get_attribute("href")
Select(link)
This code has just grabbed what had better be a SELECT tag, but it certainly looks as if you've grabbed only an href. You tried to create a Select object from that link ... but then, having created it, you failed to save it: you threw it away.
Select.click()
I'm not at all sure how you expect this to work: this invokes click as a direct call of a class method, but Select has no such method, so this will fail because teh attribute doesn't exist: an error message you failed to provide in your posting.
Start with this: once you work through your tutorial materials and learn to extract the proper SELECT tag from a URL i ... perhaps
select_tag = i.find_element_by_tag_name(“select”)).select_by_index(0)
clickable = Select(select_tag)
clickable.click()
You click on the object you created, not on the class.
Does that help get you going? You still need to figure out how to code that first line in your application.
I'm a beginner in using Nightwatch and I'm stuck with the following:
I've got a table that has a <tbody> and multiple <tr>s in it. I need to check if a specific word is in one of the cells in the first column.
First, I tried getting the whole table using document.GetElements... but it appears this is not supported by Nightwatch. Currently, I'm looking for a solution without using Nightwatch custom command.
P.S. I can't create tags yet, so it'd be awesome if someone could create one, like table-to-array or something like that.
You can execute javascript code into the browser using execute command (Documentation here). So you can do something like this:
client.execute(function(){
/*your js to get the DOM element and check if the element has the text you want*/
return true //or false if didnt find it
},[],function(response){
console.log(response.value)//this will contain your returned value
client.assert.equal(response.value, true, "Text not found on table")
})
Please take a look here: http://www.binarymark.com/Products/FLVDownloader/order.aspx
What I am trying to do is to get rid of the prices inside the option tag. On that page you can see a drop-down box under Order Information, Product. I want to remove the prices from all the options that contain them in that box, so get rid of " - $75.98" for example. I am not used to JQuery, but I realize it would be possible - just not sure how to do it, so your help would be greatly appreciated.
Thanks.
George
Something like this should do the trick:
$('select[name="contractId"] > option').each(function ()
{
var $this = $(this);
$this.text($this.text().split(/\s-/)[0]);
});
That should split the text into an array with the "wanted" part as index 0, and set the text to whatever is contained in that index. You could also use a replace regex if you wanted to.
It would make more sense to do this server-side really, if a user has JS disabled on their machine you could run into problems with displaying incorrect prices.
Unfortunately based on your country of origin, Plimus is not allowed to continue this process. So I cant help you! :)
but this is the general idea:
if ($('#field > div.field-item:contains("someText")').length > 0) {
$("#somediv").addClass("thisClass");
}