Does RobotFramework have any way of finding a link's URL to then paste into same browser and goto it in same window. The link exists in a button/link on the first page.
Reason i ask is because it opens a new window (which i dont want it to do)
You can use Get element attribute to get the value of the href attribute.
Here is an example using an xpath to find the element:
*** Settings ***
Library Selenium2Library
Suite Setup open browser about:blank chrome
Suite Teardown close all browsers
*** Test cases ***
Example
go to http://www.example.com
${url}= get element attribute xpath=//a[text()='More information...'] href
Should be equal ${url} http://www.iana.org/domains/example
Related
I try to create a program which will automate fetching data from one of the Google services. By using chrome and watir (which is basically a Ruby library build on top of the Selenium). Everything works fine as long as I keep my browser open. But when I minimize window, my program is not even able to pass a login process since it cannot find certain elements. This is my code to login:
#browser = Watir::Browser.new :chrome, options: { detach: true }
#browser.goto BASE_URL
#browser.text_field(name: 'identifier').set USER_EMAIL
#browser.element(xpath: '//*[#id="identifierNext"]').click
#browser.text_field(xpath: '//input[#type="password"]').set USER_PASSWORD
#browser.element(xpath: '//*[#id="passwordNext"]/div/button/div[2]').click
When my browser is minimize, during attempt to set a password I get this error message:
*** Watir::Exception::UnknownObjectException Exception: element located, but timed out after 30 seconds, waiting for
#<Watir::TextField: located: true; {:xpath=>"//input[#type="password"]", :tag_name=>"input"}> to be
present
And it works just fine as an open window. Even if I maximize the window during whole process program is suddenly able to locate missing input fields. The same story goes in many other points further. Program is not able to locate some elements unless chrome window is open.
Needless to say it works even worse in headless mode and I'm basically not able to locate any of those elements in html code.
As far as I understand Google services frontend side are build with Angular framework which inject html code dynamically. But shouldn't selenium pretend to act like a regular user and trigger the same responses on minimized and open window (and the headless mode as well)?
Is is some kind of blockade from Google to prevent this kind of automated proces and how can I bypass it?
Is this an issue with Chrome and switching for e.g. Firefox would fix it?
Can I implement some additional actions to actually mimic human interaction and pretend that my Chrome window is open?
We have an cypress issue that is similar to the issue described in "https://github.com/cypress-io/cypress/issues/850". The reason for why I am creating a new post is that I have done some changes in the environment which makes this work but only after the first fail and then manually click on the failing URL.
Test1:
Default cypress\plugins\index.js file (no changes)
lauch the internal page cy.visit('xxx')
Error 401.
Click on the link below the error text. Another tab is opened and message UNAUTHORIZED is shown.
Paste same URL in default Chrome->works fine.
Test2:
Modify the cypress\plugins\index.js: args.push('--proxy-pac-url=xxx') (I have tested other arguments but this is the only one that makes something different)
Lauch the internal page cy.visit('xxx')
Error 403.
Click on the link below the error text. Another tab is opened and the page is shown CORRECTLY.
This is the reason why I post this new message. I want to ask if there is a way to get Cypress to open the page automatically via cy.visit() in the same way as when I click on the failing URL and it opens the page in the same cypress browser but just another tab?
I have been hit with InvalidSelectorException on a regular basis when i run my selenium web driver test script
My test fails with this InvalidSelector Exception and throws message as :
The xpath expression '//form[#name=somelocator]' cannot be evaluated or does not result in a WebElement
The element locator i use is perfect which return a correct web element when i cross verify it using xpath checker / or with browser console, so no issue with the element locator
I click on some button and then wait for the above xpath locator element to load in the application UI and giving enough waitTilllElementVisible() methods before checking the above locator
I found that many faced this issue, but could not get the concrete reason for this failure.
Selenium asks to visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html for the documentation on this error, but this link looks not up
Reproduced it with selenium 2.45 and 2.46 version with IE11
Please let me know if you knows the reason for this and why it throws invalidSelector exception on browser open with webdriver
I think the problem is the SPACE character in the #name tag. Try "//form[#name='some locator']" or '//form[#name=\'some locator\']'.
#peetya's answer is probably correct and a better answer but I prefer CSS Selectors... they are less error prone if you have the option to not use XPath.
driver.findElement(By.cssSelector("form[name='some locator']"));
CSS Selector reference
Is there a universal way to detect when a selenium browser opens an error page? For example, disable your internet connection and do
driver.get("http://google.com")
In Firefox, Selenium will load the 'Try Again' error page containing text like "Firefox can't establish a connection to the server at www.google.com." Selenium will NOT throw any errors.
Is there a browser-independent way to detect these cases? For firefox (python), I can do
if "errorPageContainer" in [ elem.get_attribute("id") for elem in driver.find_elements_by_css_selector("body > div") ]
But (1) this seems like computational overkill (see next point below) and (2) I must create custom code for every browser.
If you disable your internet and use htmlunit as the browser you will get a page with the following html
<html>
<head></head>
<body>Unknown host</body>
</html>
How can I detect this without doing
if driver.find_element_by_css_selector("body").text == "Unknown host"
It seems like this would be very expensive to check on every single page load since there would usually be a ton of text in the body.
Bonus points if you also know of a way to detect the type of load problem, for example no internet connection, unreachable host, etc.
WebDriver API doesnot expose HTTP status codes , so if you want to detect/manage HTTP errors, you should use a debugging proxy.
See Jim's excellent post Implementing WebDriver HTTP Status on how to do exactly that.
If you just need to remote-control the Tor Browser, you might also consider the Marionette framework by Mozilla. Bonus: It fails when a page cannot be loaded: (see navigate(url) in the API)
The command will return with a failure if there is an error loading
the document or the URL is blocked. This can occur if it fails to
reach the host, the URL is malformed, the page is restricted (about:*
pages), or if there is a certificate issue to name some examples.
Example use (copy from other answer):
To use with the Tor Browser, enable marionette at startup via
Browser/firefox -marionette
(inside the bundle). Then, you can connect via
from marionette import Marionette
client = Marionette('localhost', port=2828);
client.start_session()
and load a new page for example via
url='http://mozilla.org'
client.navigate(url);
For more examples, there is a tutorial.
I am looking at the website. Trying to transfer selenium html to junit but could not get it to work because it keeps saying Error: Element not found. Maybe syntax error because I was able to break it down to the shortest path in firebug but still could not get to compile..What do you do in this case ?
Enrollment
I use firebug Xpath to get the value of the above link
/html/body/div[#id='contentDisplayPane']/div[#id='mainDiv']/div[#id='mainDivContent']/div[#id='simpleBox']/table/tbody/tr[2]/td[#id='fb_PageContent']/table/tbody/tr/td/table/tbody/tr/td[4]/a
Using firebug xpath, I was able to break it down to this and able to access Enrollment link..However when I put this in the junit test case selenium.click(("//div[#id='simpleBox']/table/tbody/tr[2]/td[#id='fb_PageContent']/table/tbody/tr/td/table/tbody/tr/td[4]/a");
I get ERROR: Element //div[#id='simpleBox']/table/tbody/tr[2]/td[#id='fb_PageContent']/table/tbody/tr/td/table/tbody/tr/td[4]/a") not found
Any help or tip is appreciated
Hey If you want to click any Link on your web page.
You have to first find Xpath of this Element/Text, For this you can use Firebug.So here an ex: You can use in IDE selenium.click(//a[text()="ON"]) and convert it to junit and get this
selenium.click("//a[text()=\"HereYouCanPutYourText\"]");
please feel free if you have any concern..
Are the tbody elements actually in the html or just being inserted by Firefox? If Firefox is inserting the tbody and your junit tests are driving a different browser, the tbody might not be there. Just a shot in the dark since you didn't post the document you're testing, but maybe it'll help.