I am using simple project, where you fill in the form. The last part is to click on a element with no id and no text.
I found that i could use java to do it, but how do i initiate the driver in selenium?
Actions builder = new Actions(driver);
builder.moveToElement(knownElement, 10, 25).click().build().perform();
I tried
WebDriver driver = New ChromeDriver();
but that only raised a lot new problems. I am using IntelliJ.
You need chromedriver.exe to initiate selenium web driver.
First download the ChromeDriver. You need to download ChromeDriver for your respective Operating system from this link
//Then set the download location.
System.setProperty("webdriver.chrome.driver", "C://Selenium-java//chromedriver_win32//chromedriver.exe");
//Creating an object of ChromeDriver
WebDriver driver = new ChromeDriver();
//launching the specified URL
driver.get("https://www.google.com/");
Then find your element to be clicked using xpath.
If you say you don't have any id or text for click then use any parent element as reference which you can identify then use xpath axes to identify it.
Then you can click on that element directly.
driver.findElement(By.xpath("//form[#id = 'id']/child::button")).click;
Related
I'm working on the secured web application. When I click link within frame, it opened another single window where information to be filled.But when I execute this scenario in selenium, it click the link within frame and system display two windows where window1 shows Blank page with title as "Blank Page- window internet explorer' and window2 shows website security certificate with no title.
When I'm doing manually, it showing single window but during automation, it shows two windows.
Note: Application support only IE10.
script:
System.setProperty("webdriver.ie.driver","./tools/IEDriverServer_32.exe");
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
caps.setCapability("ignoreZoomSetting", true);
WebDriver driver = new InternetExplorerDriver(caps);
driver.get(url);
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
Login the application and next step to click link
driver.findElement(By.xpath(".//table[#id='maintable']//a").click();
Please help me on this.
I encountered the exact same issue in IE 10..The issue appears to be resolved when I am setting "nativeEvents" to true using the DesiredCapabilities Class. You may try the same and let us know if it also works for you. Please find code segments for your reference:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability("nativeEvents", true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
The 2nd Line seems to do the trick.
The below solution worked
Modifying the registry value , TabProcGrowth to 0 solved the issue-
Go to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
TabProcGrowth (right-click) → Modify… → Value data: 0
which version of selenium jar are you using. Try below code...
System.setProperty("webdriver.ie.driver","./tools/IEDriverServer_32.exe"); WebDriver driver = new InternetExplorerDriver();
driver.get(url); driver.navigate().to("javascript:document.getElementById('overridelink').click()");
if this not works.... last option, please Reinstall IE and problme will be fixed.
I am trying to navigate to www.google.com and send some inputs to search box using Selenium webdriver with Internet Explorer(IE).
static WebDriver webDriver = null;
static DesiredCapabilities IEDesiredCapabilities = DesiredCapabilities.internetExplorer();
System.setProperty("webdriver.chrome.driver", TestConstants.chromeDriverFilePath);
System.setProperty("webdriver.ie.driver", TestConstants.IEDriverFilePth);
IEDesiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
webDriver = new InternetExplorerDriver(IEDesiredCapabilities);
//webDriver = new ChromeDriver();
webDriver.navigate().to("http://www.google.com");
webDriver.findElement(By.name("q")).sendKeys("Venkatesh Kolisetty");
//webDriver.findElement(By.id("lst-ib")).sendKeys("Venkatesh Kolisetty");
This piece of code runs very well when i use Chrome, but throws org.openqa.selenium.NoSuchElementException when IE is used.
This opens required web page in the IE browser which is opened by selenium. The problem is selenium is not able to find any element after page is loaded only when IE is used. For chrome, it finds required elements.
Is there any capability to be added in IEDesiredCapabilities
Kindly see the possibility of providing a programmatic solution instead of changing internet options manually.
Yes this is common issue when you use IE.
Open regedit.exe
Open HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
So Zones will contain 0,1,2,3,4 and on right hand side three columns will be visible as soon as you click on 0 i.e. Name Type Data
Now in Name column look for 2500 Double click it. Put Value data as 3 and Base as Hexadecimal
You did this for 0.
Now repeat the same steps for 1,2,3,4..
Do this for all i.e. 0,1,2,3,4,5 => Change all 2500's value data to 3.
After that run this code.
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.ie.driver", "D:\\Selenium\\CP-SAT\\IEDriver\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("www.google.com");
It will run on IE. You need a IEDriverServer.exe as i have shown in path, which will run your IE browser.
Reply to me for further query. I ran the above code in eclipse and it ran successfully.
Happy learning :-)
Issue resolved after adding some required capabilities.
IEDesiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
IEDesiredCapabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.google.com");
IEDesiredCapabilities.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
IEDesiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
IEDesiredCapabilities.setJavascriptEnabled(true);
//IEDesiredCapabilities.setCapability("requireWindowFocus", true);
IEDesiredCapabilities.setCapability("enablePersistentHover", false);
IEDesiredCapabilities.setCapability("requireWindowFocus", true); is optional
I'm stuck on how can I open the instance of webdriver on my html page using java.
WebDriver driver = new ChromeDriver(); // Open the Application
the code below open the instance of driver chrome.
If you want to start chrome browser, first download chromeDriver from here After that we need to specify this downloaded chromedriver and then start the driver instance
System.setProperty("webdriver.chrome.driver", "\\downloaded driver path");
WebDriver driver = new ChromeDriver();
driver.get("http://URL here/");
Then as said need to switch to frame, so
driver.switchTo().frame("iframe id or name");
//or
driver.switchTo().frame("index like 0, 1");
//or
driver.switchTo().frame(driver.findElement(By.xpath("//iframe"))); //iframe location
//after work in frame is completed, then we need to switch back to default content
driver.switchTo().defaultContent();
Thank You,
Murali
I'm using Selenium WebDriver (Java) and am trying to change the URL after WebDriver has logged into a page.
Is there a way to either:
Change the URL of the current window, or
Open a new tab and go to another page.
Thanks!
You didn't share any code so i don't know how is your approach about it, I only share my knowledge about this subject.
1) For your first question i think you know how to open a new page with selenium web driver maybe you can use some wait method and then invoke the driver again.
//open browser
driver = new FirefoxDriver();
//login
driver.get("https://www.google.com/");
//set implicit wait
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Then invoke method again for your second request(I am not try this code maybe you need to create new driver object)
driver.get("https://www.stackoverflow.com");
2) For your second question this link help you.
I have a text box in which when I type one letter say 's' , it displays a list of results ( like google search) .
I am using latest selenium webdriver with java.
I have tried
sendKeys("s"),
JavascriptLibrary jsLib = new JavascriptLibrary();
jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onkeyup");
jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onblur");
jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onclick");
jsLib.callEmbeddedSelenium(driver, "doFireEvent", driver.findElement(By.id("assetTitle")), "onmouseup");
driver.findElement(By.id("assetTitle")).sendKeys(Keys.ENTER);
None of these work even after adding wait after each of the steps.
Any suggestions?
Thanks.
Update :-
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement query = driver.findElement(By.name("q"));
query.sendKeys("s");
driver.findElement(By.xpath("//table[#class='gssb_m']/tbody/tr/td/div/table/tbody/tr/td/span")).click();
driver.findElement(By.name("btnG")).click();
Update 2 : -
WebDriver driver = new FirefoxDriver();
driver.get("http://www.kayak.com/");
WebElement query = driver.findElement(By.name("destination"));
query.sendKeys("s");
Update 3 :-
I tried with Selenium 1 and the fireevent method works by passing parameter as 'keydown'. This should be a temporary workaround for now.
WebDriver driver = new FirefoxDriver();
driver.get("http://www.kayak.com/");
DefaultSelenium sel = new WebDriverBackedSelenium(driver,"http://www.kayak.com/");
sel.type("//input[#id='destination']", "s");
sel.fireEvent("//input[#id='destination']", "keydown");
I found a workaround about this. My problem was:
Selenium inputted 'Mandaluyong' to an auto-suggest location field
The auto-suggest field appears together with the matched option
Then selenium left the auto-suggest drop-down open not selecting the matched option.
What I did was:
driver.findElement(By.name("fromLocation")).sendKeys("Mandaluyong");
driver.findElement(By.name("fromLocation")).sendKeys(Keys.TAB);
This is because on a manual test, when I try to press TAB key, two things were done by the system:
Picks the matched option from the auto-suggest drop-down
Closes the auto-suggest drop-down
I believe you are testing auto-suggest here (not auto-complete)
Steps I follow -
Enter something in the input field
Click on the suggestion you want to choose. (You can find the xpath using some tools like Firebug with Firepath, Chrome, etc.)
Verify the text in the input field is same as expected.
This should be a temporary workaround for now.
WebDriver driver = new FirefoxDriver();
driver.get("http://www.kayak.com/");
DefaultSelenium sel = new WebDriverBackedSelenium(driver,"http://www.kayak.com/");
sel.type("//input[#id='destination']", "s");
sel.fireEvent("//input[#id='destination']", "keydown");