Cannot find web elements at "chrome://downloads/" page - java

I am using Java and Selenium to write tests for Chrome. Sometimes I need to get to chrome://downloads/ and click on CLEAR ALL button. I can get to the page by
RemoteWebDriver driver = (RemoteWebDriver) driverChrome;
driver.executeScript("window.open();");
Thread.sleep(500);
tabs = new ArrayList<String>(driverChrome.getWindowHandles());
driverChrome.switchTo().window(tabs.get(1));
Thread.sleep(500);
driverChrome.get("chrome://downloads/");
but I cannot click on the button, whatever xpath I use it says no such element

Below here JavascriptExecutor example to perform click on CLEAR ALL button using selenium :-
JavascriptExecutor executor = (JavascriptExecutor)driver
executor.executeScript("var dm = document.getElementsByTagName('downloads-manager')[0];var toolbar = dm.shadowRoot.getElementById('toolbar');var actions = toolbar.shadowRoot.getElementById('actions');actions.getElementsByClassName('clear-all')[0].click();");
Tested in Chrome Version 50.0.2661.102 m
Hope it will help you..:)

Related

Side menu does not appear whenever I change zoom in selenium + java

I am currently working in a selenium with java automation proyect.
The web page I am automating opens a side menu depending on the size of the screen. In my case, it does not open it. To solve this you can either clic on the menu button to open it or change the zoom.
I am trying to implement the second solution zooming (this is the solution I need):
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.body.style.zoom='70%'");
The zoom works but the side menu does not appear. Is there anything extra that I need to do?
I also use the next line as part of my configurations:
ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=1980,1080");
I also tried different ways to zoom in but the results are the same:
driver.findElement(By.tagName("html")).sendKeys(Keys.CONTROL,Keys.SUBTRACT);
WebElement html = driver.findElement(By.tagName("html"));
new Actions(driver)
.sendKeys(html, Keys.CONTROL, Keys.SUBTRACT, Keys.NULL)
.perform();
Any suggestions? I would appreciate them because I am new to selenium and I am pretty stuck with this issue.
driver = new ChromeDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
driver.get("chrome://settings/");
jse.executeScript("chrome.settingsPrivate.setDefaultZoom(0.9);");
driver.get("...");
This is how I managed myself to do zoom correctly.

Xpath selector not working in IE but working fine in Chrome and Firefox

I am using following xpath to click on element using JSExecutor in Selenium webdriver. This works fine in Firefox and chrome but does not work in IE.
Any idea to make this work? After lot of trial and error I have made this work in FF and chrome and have come up with the following XPath.
//*[contains(#class,'ui-select-choices-row') or contains(#id,'ui-select-choices-row')]//*[text()='TextofMyElementToBeclicked'
Additional info: This is a Jquery drop down on an angularJS application. When the user clicks on the drop down //ul is loaded and i am using the above xpath (which is part of //ul) to select the element based on text (using Javascript executor click). I used JS executor because, click() function in selenium simply could not click on the drop down element.
I am clicking element using below.
WebElement element = driver.findElement(By.xpath("YourNumbersXpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
enter code here
I successfully tested your XPath with IE11, so it's not an issue related to IE. It's most likely a timing issue. First click on the drop button, then wait for the targeted element to appear and finally click on it:
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get("...");
// move the cursor to the menu Product
WebElement element = driver.findElement(By.xpath("drop down button")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("drop down item"))).click();
IE11 seems to struggle with contains(#class and possibly also the contains(#id. Try using alternative solutions like starts-with.

Clicking on an element in Selenium to bring up File Upload window doesn't work

In facebook navigate to Home and try to click on Add Photos/Videos to bring up the file upload window but it always gives an exception "Element is not clickable at point ..."
I tried the methods given in the first answer of Debugging "Element is not clickable at point" error
but nothing works.
Edit:
Code:
1.
WebElement element= driver.findElement(By.xpath("//span[text()='Add Photos/Video']"));
element.click();
2
WebElement element= driver.findElement(By.xpath("//span[text()='Add Photos/Video']"));
element.sendKeys(Keys.RETURN);
3
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();
4.
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", element);
You can use Actions moveToElement
Actions actions = new Actions(driver); // initialize Actions instance
actions.moveToElement(elementToClick).performe(); // scroll the screen to make the button visible
elementToClick.click();
I just tried this and it worked... the File | Open dialog opens.
driver.findElement(By.cssSelector("div._3jk")).click();
Try this:
IJavaScriptExecutor ex = (IJavaScriptExecutor)Driver;
ex.ExecuteScript("arguments[0].click();", elementToClick);

Selenium - Java - Unable to click a link

My problem mainly is that my code doesn't run, I tried for more than 2 hours. I have seen many posts also, but some are written in different computer languages (not in Java), so I am confused now.
Below is my code for just clicking a button. All I want to do is click a button and go to new page.
WebDriver driver = new HtmlUnitDriver();
driver.get("file:///C:/Users/Sanya/Desktop/New%20folder%20(2)/page%203%20alerts.htm");
WebElement element = driver.findElement(By.partialLinkText("Alert"));
element.click();
Try this it works fine for me:
WebElement menuHoverLink = driver.findElement(By.id("your_id"));
actions.moveToElement(menuHoverLink).perform();
You can try the below one...
Actions action = new Actions(driver);
action.click(driver.findElement(By.partialLinkText("Alert"))).build().perform();
It was worked for me :-)
You can use XPath for instance to locate the element on your page:
By locator = By.xpath("//li[#title='Alerts']/a");
WebElement element = driver.findElement(locator);
Here is more information about how XPath works.

How to click on Hidden link through Selenium Webdriver

I am unable to click on a hidden link through Selenium Webdriver.
I am using the below code:
WebElement dwnld = driver.findElement((By.xpath("////form[#id='aspnetForm']/div[6]/div[2]/div/table/tbody/tr[3]/td[2]/table/tbody/tr[2]/td/a")));
Actions builder = new Actions(driver);
Action hoverAction = builder.click(dwnld).build();
hoverAction.perform();
If you don't want to show the link before clicking on it for some reason you can use javascript to click on it (see JavaScriptExecutor).
String Block1 = driver.findElement(By.id("element ID"));
JavascriptExecutor js1=(JavascriptExecutor)driver;
js1.executeScript("$("+Block1+").css({'display':'block'});");

Categories

Resources