Selenium didn't click second time after being reloaded to homepage - selenium

I have a test case here:
My page left part is an accordion menu. When I performed click parent menu, it worked. And the right part of the website will display "You do not have authority" and return me back to the homepage.
The right part will display normal content when I second visit. So I should click the menu again and I write like so in my test code. But it didn't perform any click action - just passed the click action to the next step. So my test fails and throws error.
I looked at my browser which is controlled by selenium webdriver. It is apparently frozen after the page reloads to the homepage.
The error message shows:
Test method AutomationTesting.cuteTest.CheckChocolate threw exception:
OpenQA.Selenium.WebDriverTimeoutException: Timed out after 5 seconds ---> OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#class='menuChocolate']/a"}
My test code: (Why I have to click the second time is because this page needs to come the second time to show the normal UI)
DessertsMenu.Click();
WebDriverWait waitForMenu= new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
waitForMenu.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[#class='menuChocolate']/a"))).Click();
DessertsMenu.Click();
WebDriverWait waitAgain= new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
waitAgain.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[#class='menuChocolate']/a"))).Click();
I looked at the browser which is controlled by selenium, it actually clicks the menu. But I don't know why it didn't click again.
Is there anything I am missing?

If the page is reloaded, I think you will have to locate the parent menu again.
If, even after locating the element, you are not able to click the parent menu, then I would suggest you to try clicking the parent menu using JavaScriptExecutor.
https://www.guru99.com/execute-javascript-selenium-webdriver.html

You can troubleshoot it with below options--
can you check after first click if it is showing the same xpath ,it might be possible that after clicking xpath is getting changed
you can put some wait like one second between first and second click
3.If above two options are not working then you can use JavaScriptExeccutor

Related

ElementClickInterceptedException: Message: element click intercepted: Other element would receive the click - Click Element or Button Failing in Robot

Click Element or Click Button is not working in Robot Framework.
Simple Code Block for Login page
${chromeOptions}= Create Dictionary acceptInsecureCerts=${True}
Open Browser ${url} ${browser} desired_capabilities=${chromeOptions}
Maximize Browser Window
sleep 5s
Wait Until Page Contains Welcome to Mavenir CMS.
Input Text name:user name ${username}
Input Text name:password ${password}
Wait Until Page Contains Element xpath://button[#type="submit"]
Click Button xpath://button[#type="submit"]
# Press Keys \ ENTER
sleep 15s
Wait Until Page Contains Element xpath:${home_settings}
Actually the same code was working till the previous version of same dashboard. Now am getting the error while trying to Click Element
The code passes till Wait Until Page Contains Element xpath://button[#type="submit"]
The element is loaded and its available but when I try to click it, its not happenening.
I have tried providing different ways of locators like below for the same button:
xpath://button[contains(text(),'Login')]
class:btn-primary
xpath:/html/body/my-app/div/headerapp/div/div[2]/login/div[1]/div/div/div[2]/form/div[3]/button[1]
css:body > my-app > div > header-app > div > div.col-md-12 > login > div.login-overlay > div > div > div.login-right.pull-right > form > div.group.pull-top-2 > button.btn-primary
and the one seen in the code block above.
All these are returning the same exception --> ElementClickInterceptedException
I have tried adding sleeps in between also and still same issue.
One thing that worked is, instead if Click Element/Button, I gave Press Keys \\ ENTER
It worked and login was successful but once logged in to the dashboard, again when I try to click on any other elements/tabs inside, getting the same exception. So basically I was able to everything other than Click operation but Clicking is the most important thing that is needed.
Unable to find the solution to this. Any help is much appreciated. Thanks
This happens when a page loads for a brief moment and then the element disappears for a loader or any async request.
Wait Until Page Contains Element xpath://button[#type="submit"]
Wait Until Element Is Visible xpath://button[#type="submit"]
Sleep 2s #This could be adjusted as per the time your application takes to load after first appearing. Usually this should be enough.
Wait Until Element Is Visible xpath://button[#type="submit"]
Sleep 2s
Wait Until Element Is Enabled xpath://button[#type="submit"]
Click Element xpath://button[#type="submit"]
Also, use Click Element instead of Click Button. Sometimes, very rarely, even though the element is a button, Click Button doesen't work.

How can I reach the elements of the appeared pop-up using selenium?

In the following ecommerce site "https://www.gittigidiyor.com/", I want to click on "giris yap" button using selenium java but the problem is whenever I hover the mouse to profile icon, this pop-up appears and i try to inspect the pop-up to see the element but nothing happened. Could you please help me how can i click the buttons of this pop-up. I tried by switching to alert/frame but it did not workopened login popup in the site
driver.get("https://www.gittigidiyor.com")
driver.findElement(By.cssSelector("[title=\"Giriş Yap\"]")).click()
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[data-cy=\"header-login-button\"]"))).click();
To find the element use below technique:
To search xpath of such dynamic elements use DOM break points:
And select break on subtree modification. Now all changes will break and pause the webpage rendering
Click resume execution or press f8 till your span gets displayed

How to select a popup in an iframe with robot framework / selenium

I want to write a testcase for a webapplication with Robot framework and the selenium library. The situation is that when a button is clicked, a popup page is shown withtin the webpage.
This popup is inside an iframe and has it's own etc.
I have a test that verifies if the popup page is opened by searching for presence element x.
Things I have tried are:
1a. Select frame xpath=xpath iframe
1b. Element text should be xxx
2a. Switch window title=title of popup that can be found within the element.
2b. Element text should be xxx
In both situations the test fails. The popup page is opened but the error messages shown are:
Element with locator 'iframe' not found.
Unable to locate window with title 'xxx'.
I searched for similar problems but didn't find any solutions thats helps my case.
try this
Select Frame css:iframe[id^="PopupBoxIframe_"]
where id=yourid
to get back lateron you use
unselect frame

Selenium IDE element not found select an option from dropdownlist

I'm new to selenium
My script is to:
open one website
click one button and then open go to another website
a drop down list will be shown in the new website, i need to select one option from the list
But I failed.
The log said:
Element id=primaryroles not found
I tried to change the target to detailed HTML element, like
//html/frameset/frame/html/body/form/table/tbody/tr/td/div[#id='clientBackground']/table/tbody/tr/td[2]/table/tbody/tr[3]/td/label/select
But it failed as well.
I think the problem may be that new website did not load fully, so i add command "waitforpagetoload" value30000 but the error is time run out
I run out of my brain, please help me :)
The weirdest thing is that i could execute this single command successfully, but i play this current test suit/case, it will fail when it come to this command.
As per the snapshot (without any visibility to your script) you have shared to select from the DropDown you have to use the following Algorithm :
Open one Website
Click one button and then open go to another website
Switch to the Frame with proper WebDriverWait
Use Select Class to identify the DropDown element.
Induce WebDriverWait for your target option to render in the HTML DOM
Click on the intended option

Element not visible as both the menu and submenu hidden

I want to open cric info and then click on 'live score'menu when the submenu opens, click on 'Desktop scoreboard'.
But the problem is live score menu is under a div which is hidden.
ie and this div is under td
"You can check the structure of the page to get detailed info"
so when i try to click the menu element using driver.findElementBy("xpath") i got the element not visible exception.
So i directly used the javascript used by the developer mopen('m2') which does the job of opening the menu but after this when i execute the command to find the submenu element again get the same error"Element not visible exception".
Tried making div visible by executing jscript.
PFB the code i used:
FirefoxDriver d1=new FirefoxDriver();
d1.get("http://www.cricinfo.com");
((JavascriptExecutor) d1).executeScript("mopen('m2')");
((JavascriptExecutor) d1).executeScript("document.getElementById('m2').style.visibility='visible';");
((JavascriptExecutor) d1).executeScript("document.getElementById('m2').style.display='block';");
d1.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
d1.findElementByXPath("//*[#id='mgDdRht']/tbody/tr[3]/td/a").click();
Also tried using the Actions class but everything in vain ,help is really appreciated
Thanks in advance.
You should be able to do this with an Action chain:
Actions builder = new Actions(d1);
Action clickSubMenu = builder.moveToElement(d1.findElement(By.cssSelector(".Nav td:nth-child(2).navLinks")))
.moveToElement(d1.findElement(By.cssSelector("#m0 td:nth-child(1)#mgDd>table:nth-child(1)>tbody:nth-child(1) td:nth-child(2).PopupTabs")))
.click(d1.findElement(By.xpath("//*[#id='mgDdRht']/tbody/tr[3]/td/a"))).build();
clickSubMenu.perform();
I tested this in c#, and it worked for me. I translated it to Java, but I may have made a syntactical error. Apologies if I have.
What I found is that I needed to move to Series. Then I had to move to Series - the dropdown version, as the dropdown version of Series is a different element than the non-dropdown version. Then I was able to move to the West Indies link, and click it.