I am using FirefoxDriver webdriver. The page that loads in Firefox window is a large page and I want to scroll that page using selenium.
I want to know how this can be done.
If you want to scroll on the firefox window using selenium webdriver, one of the way is to use javaScript in the java code, The javeScript code to scroll down is as follows:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight," + "document.body.scrollHeight,document.documentElement.clientHeight));");
I think you should do something like
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Good Luck.
Use this code to scroll single page down
Actions actions = new Actions(driver);
actions.sendKeys(Keys.BACK_SPACE).perform();
page.driver.browser.mouse.move_to( find("element").native,100,100)
Related
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.
After testing logging in https://www.pcbway.com/ I want to test logout.
In order to do this I need to hover on a div so that the sign out button appears. I tried using
Actions actions = new Actions(driver);
actions.moveToElement(element).build().perform();
but it did not work. I tried using the javascript exector
JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element);
but it also did not work. I can see that the hover works by using mouseout jquery (screenshot below)
I am using chrome 58 with selenium 3.4.0.
You can try to force it open by adding the class the element receives when the menu is open.
executor.executeScript("$('.nav-user-account').addClass('user-account-unfold')")
Then you can click the element in the menu.
webDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.xpath("html/body/div[1]/section[1]/div/div/a/button")).submit();
'View positions' button is not clicking with the above code.What is happening in the web page?
You see the HTML for this page is
So, you can use the CSS selector for this as
WebDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.cssSelector("button.button.teal").click();
And then proceed with doing whatever is necessary. I executed with this in my Python code and it works fine.
Also, you will need to provide the Gecko executable path while calling for the FirefoxDriver()
The way I have done it before is to use the click handler.
driver.findElement(By.cssSelector(".profile-actions .primary_button > span")).click();
I'm sure you could also select the element by xpath rather than CSS in the above line. It's a similar question to this one.
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..:)
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.