Not able to click on a button in selenium webdriver - java

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.

Related

i want to run a program to perform click on google apps icon using Selenium WebDriver but on running the code, it directs to google product page

I want to run a program to perform click on google apps icon using Selenium WebDriver but on running the code, it navigates to google product page.
Pease help me to fix this issue.
driver.get("https://www.google.com");
Thread.sleep(3000);
driver.manage().window().maximize();
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='gbwa']/div[1]/a")).click();
Try this-
driver.findElement(By.xpath("//*[#id='gbwa']")).click();
or
driver.findElement(By.xpath("//*[#id='gbwa']/div[1]")).click();
Please try to click on the link and not on the div.
Use one of these selectors:
Xpath: //*[#id='gbwa']//a[contains(#href, 'options')]
css: #gbwa a[href*=options]
this works for me:
driver.findElement(By.xpath("//a[contains(#class, 'gb_b') and contains(#class, 'gb_4b')]"));
Hope it helps.
System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.findElement(By.cssSelector("div.gb_Lf")).click();
WebElement ele=driver.findElement(By.xpath("//iframe[contains(#id,'I0')]"));
driver.switchTo().frame(ele);
driver.findElement(By.xpath("//*[text()='YouTube']")).click();

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.

Selenium Webdriver clickAndHold() error on Firefox

I try to select multiple options from list but it does not select particular option it select from first choose options to last choose option and give some error like:
Cannot perform native interaction: Could not get node for element - cannot interact
My code is looks like
WebDriver driver=new FirefoxDriver();
driver.get("http://jqueryui.com/selectable/");
driver.manage().window().maximize();
driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0));
WebElement multiSelectDropDown=driver.findElement(By.className("ui-selectable"));
List<WebElement> dropdownlists = multiSelectDropDown.findElements(By.tagName("li"));
Actions builder=new Actions(driver);
builder.clickAndHold(dropdownlists.get(0)).
clickAndHold(dropdownlists.get(4)).click()
.build().perform();
Can any one tell me why this is not working is there any problem in my code.
I think you need to change this
builder.clickAndHold(dropdownlists.get(0)).
clickAndHold(dropdownlists.get(4)).click()
.build().perform();
This should be looks like
builder.clickAndHold(dropdownlists.get(0)).moveToElement(dropdownlists.get(4)).
release().build().perform();
because in real world click the mouse and drag to the other element so moveto another element and then release the mouse.

Selenium - WebDriver not recognizing elements but IDE recognizes same elements

I am working on a sample assignment on Thomson Holidays website (http://www.thomson.co.uk/holidays.html). On left hand side there is a Holiday Search panel. I am unable to recognize any of these elements in WebDriver. However, in IDE these elements are recognized. Need more info on this as it is the first time i am experiencing such an issue. Below is the code sample:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.thomson.co.uk/holidays.html");
driver.findElement(By.id("searchbutton")).click();
driver.findElement(By.id("holidayAttribute_1")).click();
driver.findElement(By.id("holidayAttribute_2")).click();
driver.findElement(By.id("holidayAttribute_3")).click();
Thread.sleep(5000);
Because they're in the iframe, you need switch to the iframe first.
Two lines added to your existing code as follows:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.thomson.co.uk/holidays.html");
// optional, unnecessary in your case
// driver.switchTo().defaultContent(); // make sure outside of all iframes
// switch to search frame
WebElement searchFrame = driver.findElement(By.cssSelector("iframe[src='/thomson/page/byo/search/usp.page']"));
driver.switchTo().frame(searchFrame);
driver.findElement(By.id("searchbutton")).click();
driver.findElement(By.id("holidayAttribute_1")).click();
driver.findElement(By.id("holidayAttribute_2")).click();
driver.findElement(By.id("holidayAttribute_3")).click();
The search panel is inside an iframe. As the iframe is the first iframe, you can use the below code.
driver.get("http://www.thomson.co.uk/holidays.html");
// switch to search frame
driver.switchTo().frame(0);
driver.findElement(By.id("searchbutton")).click();
driver.findElement(By.id("holidayAttribute_1")).click();
driver.findElement(By.id("holidayAttribute_2")).click();
driver.findElement(By.id("holidayAttribute_3")).click();

How to scroll page with selenium

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)

Categories

Resources