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.
Related
I am not able to click on the button, how you can see on the picture. This menu is visible, when you click on Tabellen button in the main menu. It is working manually, but when I try my selenium code, it is not working. I try different type of select it, I tried also waits. I tried xpath, cssSelector, ID. What is strange, selenium just click Tabellen button from main menu, but that menu after that just blink and nothing happen.
Please use this example. You need to correct XPath if I have made a mistake.
driver.find_element_by_xpath('//*[text()="Tabellen"]').click()
time.sleep(5)
driver.find_element_by_xpath('//*[text()="Tabellen"]//*[text()="Standorte"]').click()
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
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
I am relatively new to Selenium and it's capabilities So far I have found it's just the tool to use for automated regression testing for a web application. And it's for this regression testing suite that I am in the process of building that I have come to a problem. In the web app I have a page that displays a Jquery Datatable with some rows in it. Each row is bound with a context menu. That pop's up as a DIV floating on the top most Z-order, with absolute positioning all controlled with Jquery.
What I am attempting to do in selenium is to physically use this menu so that I am able to warp it with the appropriate regression tests. I have has some success with using the Actions class to call the context menu up. What I am not able to do is to have the mouse move to the menu Items can click them. I have been trying to use the MoveByOffset method but I don't seem to be having any luck in getting it to click on anything in the menu. I also have had no luck in working out where on the page the mouse is currently located thus not able to prove is anything is actually happening.
any help or advise on this will be gratefully received.
Thanking you all in-advance.
This is the code that I am currently using to attempt to drive this context menu. the values in the MoveByOffset have literally been every combination of 10 & -10. to try and hit the first menu item.
public void ClickAction_myPOTSIcontextmenu(IWebElement Row)
{
Actions builder = new Actions(this._driver);
IAction action = builder.MoveToElement(Row).ContextClick().MoveByOffset(-10,-10).Click().Build();
action.Perform();
}
Hope this helps,
WebElement element = driver.findElement(By.cssSelector("selector_for_element"));
Locatable hoverItem = (Locatable) element;
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.click(hoverItem.getCoordinates());
I am using Selenium 2.0 for C# to find a radio button and click it. The code is as below:
IWebElement t = driver.FindElement(By.XPath("//table[#id='ctl00_Main__objObjectivesFeedback_ctl39']/tbody/tr/td[2]/input[#type='radio']"));
t.Click();
If I do a Console.Write(t.GetAttribute("name")), it returns the correct element name, however, click does not work.
Btw, I am using FireFox 3.6.20.
Try
t.SendKeys(Keys.Space);
If it works the only downside is SendKeys does not wait for the page to finish loading if the event caused the page to reload. Usually not a problem for radio buttons but it's something to keep in mind.