Watir won't select / find the link element - watir

I've came to this problem for quite a few times now.
It appears that Watir won't find the anchor (link) element, when I want to find it by the following syntax:
#browser.link(:text => 'View page directly').click
If I try checking link presence it will say that it doesn't exist, although the link is there.
Here is the link to original source code that causes this behavior:
https://dl.dropbox.com/u/3290107/watir-test.xhtml
Why is this happening and how to fix it?
Thanks for help

This looks like a bug to me. You should report it here: https://github.com/watir/watir-webdriver/issues
browser.a(:text => "View page directly").present?
# => false
browser.as[-2].text
# => "View page directly"
browser.as[-2].present?
# => true

Related

Can't find element on page no matter what I try

I am striking out on locating an element on a search results page. I have tried locating by xpath, wait_for_element_to_be_clickable, find_element_by_link_text etc. and still can't get selenium to locate it.
If I have the driver reload the initial URL for the search page the same search results show up and not the initial search page. I've tried nuking cookies etc. This behavior exists on chrome and firefox.
Initial URL: https://elibrary.ferc.gov/eLibrary/search
just hitting the search button yields results. However I can't locate the link "General Search" at the top of the page with selenium to go back and enter new search criteria. The link is the same as the initial URL. My code to select the link and click:
try:
self.driver.find_element_by_xpath('//*[#id="srchResult"]/nav/div/ul/li[1]/a[1]').click
except:
_LOGGER.warning('Could Not Click on General Search - starting new driver')
self.driver = webdriver.Firefox(executable_path=r"/usr/local/bin/geckodriver", options=options)
Any help much appreciated.
XPath for that link is: //a[#aria-label='Return to General Search']
You can locate the element you are looking for with the following xpath:
//a[contains(#aria-label,'Return to General Search')]
or xss_selector: a[aria-label='Return to General Search']
Don't forget to put wait condition before clicking on it!
That link is
<a _ngcontent-c1="" aria-expanded="false" aria-label="Return to General Search" class="btn btn-link nav2" name="Refine" href="/eLibrary/search">General Search</a>
It has a name, which would be the preferred way to find it because it's least likely to change. The CSS selector below works.
a[name='Refine']

Puppeteer - Click on tag behind text

I am quite new to puppeteer and am stuck with trying to click on an element. In the image, that is the "i" element, I want to click on.
When I try to click it, I get the error "Node is either not visible or not an HTMLElement". I guess it is not visible, because there it the nb space in front of it.
Is there a way still to click on it? When I manually click on it, it works, so I would think that puppeteer would also be able to do it?
Thanks,
Benni
After quite some testing I found a way how to click it. First, this didnt work:
page.click(selector)
This brought up the error that specified before.
What worked now was that:
page.evaluate(function (selector) {
const elements = document.querySelectorAll(selector);
elements.forEach((element) => {
element.click();
});
}, selector);
Not sure why the element is coming up multiple times. It should be there only once.
I am not an expert with puppeteer, but happy that this worked. Maybe it helps someone else.

Opencart 2.0.3.1 Header Problems

So, I have modified the header.tpl file in OpenCart 2.0.3.1 by removing the wishlist, linking the telephone# as a click to call and added a custom class called "great-barbecue". It worked in one version that I earlier installed. When that whole thing went sideways, I started from scratch and now the wishlist still shows up, the phone# and icon are not "click to call" and my custom class is not appearing at all? Here is a link to the code I have for header.tpl in catalog/view/theme/default/template/common header template
My site chestersbbq.com/Groton
When I copy and paste the code I get an error telling me to indent all code with 4 spaces and I really don't have time for that, hence the link. I have tried it in all browsers and when I look at the source code for the page the wishlist is still there, the phone still links to contact and my custom html is not there. I don't know how to fix this.
nice site, I have found this in the open cart forums, it looks like you have to remove all instances of the wish list. Try this and let me know how it goes.
http://forum.opencart.com/viewtopic.php?t=32955

Using Watir How can i visit all the links of a web page and then sub links of the visited link

strong textI have a web page that is containing several links on it, and when we click on any link it redirect to another page that is also containing several links, like wise all links have several pages.
I want to click on all the links and when i click on first link script should click on all the links of redirected page and so on.. when it done the clicking on the links, again second links link of the first page should get clicked like wise for links.
Please any one can help me on this, I have developed the script by which I am able to click on all the links of main(first) page but not getting idea how to do that for sub pages of the application.
Please revert ASAP, its very urgent.
You just have to implement some recursive function like this:
def crawl(link)
browser.goto link
# gather all links before navigating to next link
all_links = browser.links.reduce([]) do |memo, link|
memo << link if link.href =~ /appdomain/ # do not visit external links
memo
end
all_links.each do |link|
crawl link
end
end
crawl "http://appdomain.com/"
This is untested code, but it might work :)
Also this code does not avoid clicking link to same path twice from different places - there's room for optimization.
It might be that you're using wrong tool for your job - at least it seems so when reading your question. What is the original problem?

review form do not show up after clicking on "Be the first one to review"?

i have checked that review is both enabled from Advance tab under system -> configuration and also from catalog tab.
also i have changed the files with original one but still not getting the form on frontend :( Although link to show review is showing .
can anyone please help ?
DO category settings like anchor set to NO has any impact on it ?
i did even replace complete folders of layout and template even then it didn't change. But when I commented app/design/frontend/mythemefolder,
it did show up.
But how can i show it on mytheme ?
i guess someone played with my style sheet and i found that this class ".product-collateral" in stylesheet was given "display = NOne"
it took me too long as i was examining the code but anyhow problem solved.

Resources