Not able to click link text in selenium web driver execuiton - eclipse

I am trying to click hyperlink called "order create" in my application.I have used following code.When I execute this step in eclipse debug mode or selenium IDE, I am able to click particular link.However when I try to execute via Java mode in eclipse, my code is not able to click this link.Do we have any other option to click this link?(i.e wait and click something)
Driver.findElement(By.xpath(//*[#href='link' and text()='Create Order'])).click();

You can use explicit wait with expected condition elementToBeClickable to wait for the element to be clickable
WebDriverWait wait = new WebDriverWait(Driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#href='link' and text()='Create Order']"))).click();

Hi if your drivers clicks before page load then there is a synchronization issue
simplest way to avoid synchronization issue is use of universal wait i.e implicit wait which says driver instance to wait for a maximum of defined (time seconds) before sending any error.
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
in above code you are telling driver instance to wait a maximum of 20 seconds for the individual webelements in the current session.Note above wait is applicable for all webelements.

I have used Thread.sleep(2000); before my test step.It has solved my issue.

Related

ElementNotInteractableError: element not interactable in selenium-side-runner but not in selenium IDE

I am running a Selenium .side file in selenium-side-runner and get
ElementNotInteractableError: element not interactable
(Session info: chrome=83.0.4103.61)
Same browser version, with selenium IDE runs fine.
How can I debug that?
Even the session closes after the selenium-side-runner test so I do not have a chance to look at the current state of the website.
I did not find an option like "leave session open after failure".
It looks like the IDE does a better job at implicit waiting than the side-runner. As a workaround I added pause statements to wait for the elements which are dynamically loaded.
See also https://groups.google.com/forum/m/#!topic/selenium-users/XzDQ95w9OVg
I think this is the closest issue https://github.com/SeleniumHQ/selenium-ide/issues/643

"script time out" when using protractor (there is a referenced third-party resources(google map) that takes too long to load)

I am a fresh Protractor user trying to write some Protractor E2E test.
The page I am testing has some TextInput boxes, and a app-map(google map).
When I tried to enter some charactors by using "sendkeys" function, the script failed with the error "script time out".
I assumed that it took too long for protractor to load the entire page.
For this page I just want to find the textbox elements and enter some charactors. Could anyone help me to igore the loading of the google map?
best regards
shixiang
Set browser.waitForAngularEnabled(false) in your script file this ignores the wait time to load the components.
Use expected conditions to make your script wait till the text boxes appear. here is the link for more info on expected conditions
https://www.protractortest.org/#/api?view=ProtractorExpectedConditions
Add allScriptsTimeout in your config file which will override jasmine default timeout("allScriptsTimeout: 2400000"). You can set the timeout value depending on your requirement. it's in millisec.
Hope this helps

Can I write a code in groovy in wait for page load?

I'm using Winium automation tool for desktop apps that is integrated with Katalon Studio but I'm using static wait time, like Thread.sleep().
Sometimes page load is taking more than the time what I'm putting there.
So is there any way to use groovy code that will wait until the application loads successfully?
In two ways, we can solve this issue
one increase the wait for page load option in Katalon
WebUI.waitForPageLoad(10, FailureHandling.STOP_ON_FAILURE);
Else use the custom fluent wait
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("object details")));

GWT Selenium Tests sometimes fails

we currently have a nice problem with our selenium tests in a gwt powered gui.
The application contains two sections (filter and grid). Our tests sometimes fails with a NoSuchElementException.
Crazy is the following: I stop the test in eclipse with a breakpoint and inspect the page with firefox firebug or any other addon. And okay - I cannot find the desired element. But (without restarting the application or any other changes in eclipse), if i try again and search the element it is there and a resume in eclipse the test goes green. For me it seems like a synchronize problem in firefox.
A explicitly wait command
new WebDriverWait(getDriver(), 10).until(condition);
has the only effect, that the timeout (10 seconds) happens.
As I said - sometimes the test is green and sometimes it fails.
Has anybody an idea?
Sounds like you load some data asynchronous (RPC) from the server? The data and thus the element which presents the data in the UI is not there yet, when Selenium is looking for it. Depending on how long your queries take on the database or what latency you have on the network the wait time may vary from test-run to test-run.
I have a workaround for this problem and would share this.
The following piece of code is executed before the explicit wait command is running.
Window window = getDriver().manage().window();
Dimension dimension = window.getSize();
Dimension tmp = new Dimension(dimension.getWidth() - 1, dimension.getHeight());
window.setSize(tmp);
window.setSize(dimension);
I figured out, that the DOM is in "synchronized" state after the browser window is resized. So I decrement the width and than set it back to the old value.
If anybody has a better suggestion - let us know ;-)

Selenium beginner question

I am just trying to understand and learn selenium. I used IDE to record my actions and tried to playback but I am kind of stuck on the first step.
What I am trying is basically login to our internal site and then click on menu bar to navigate to an internal page. Selenium logs in but fails at the click event with error message -
[error] Element css=#ui-active-menuitem > span.wijmo-wijmenu-text > span.wijmo-wijmenu-text not found
This site is generated using primeface and when I see the source code, the line that generate error is something like-
<div align="left" class="container"><div id="menu"><ul id="menu_menu"><li><a href="javascript:void(0)">
<span class="wijmo-wijmenu-text">Home</span></a><ul><li>home</li></ul>
</li><li><span class="wijmo-wijmenu-text">Tills</span><ul>
<li>Manage........
I must tell here that as long as I am not clicking on above menu item, I am able to run all tests through Selenium ID but clicking on above menu after login is essential to get to inner pages.
You help/guidance is much appreciated.
Thanks
I'm begining too and having same problem. This commands work for me:
clik
link=menuName
clickAndWait
link=subMenuName
Hope it helps.
Maybe element not found just because it not loaded yet.After log in you can try to use command
waitForElementPresent and then click on element.
It seems you refer to an element by css, you can try id or name
I think before appearing the menu Selenium trying to click.
Just use
Thread.sleep(5000); // for five second waiting or more you can use
Another way use -
WebDriverWait wait = new WebDriverWait (driver, 30); // maximum wait 30 seconds
wait.until(ExpectedConitions.PresenceofElement(By.id("Menu_id"))).click();
Add wait and never try learning selenium through IDE .
disadvantages of using IDE is you cannot add conditions ,loops and wait in your code and cannot maintain the framework.