In our web-aplication we use several alerts like this:
I need to retrieve link from this alert.
I did:
Alert alert = driver.switchTo().alert();
String link = alert.getText();
But alert.getText() returns "Link to copy" not a link in textfield
so how can I get link in this case?
WebDriver will be unable to retrieve the link text.
For Windows, you could leverage the Windows Automation API to scrape the text, other operating systems probably have similar APIs that you could utilize - but the short answer is that WebDriver won't be able to do this.
Related
Am trying to click on 'OK' button in the attached popup using selenium webdriver alert interface.
When I inspected the 'OK button using accessibility inspector, it has shown the below properties.
target.processes()["Google Chrome"].frontWindow().images()["Chrome critical alert"].click()
target.processes()["Google Chrome"].frontWindow().buttons()["OK"].click()
So, I have tried webdriver alert to click on 'OK', but it didnt work.
Alert alert = driver.switchTo().alert();
alert.accept();
Have spent enough time on this but couldnt find a solution.Appreciate any help here !
That doesn't look like a browser "alert" box to me, so the Alert method won't find it. It also doesn't look like a "popup" (a separate desktop window) in the usual sense. I'm guessing from your description that it's a conventional HTML element on the page. Therefore, you need to find the OK button by usual Selenium element-finding techniques and then click() on the element.
I'm clicking in on a button on a webpage using Selenium. The button creates a file which can be downloaded now. For this, a overlay is shown in Internet Explorer (yes, I HAVE to use this browser, it's a requirement).
Now I have to check the text on the overlay ("öffnen oder speichern" see my screenshot). I can imagine that it there is a solution using JavaScriptExecutor but I simply couldn't found a solution.
I also tried to find it in innerHTML-without success.
It's not an alert so I can't use Driver.switchTo().alert();
My Code still doesn't contain more than clicking on a button using XPath.
Actions action = new Actions(driver);
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
String exportButtonXPath = generalHelper.getProperty("buttonCSVExportXPath");
WebElement exportButton = driver.findElement(By.xpath(exportButtonXPath));
action.click(exportButton).perform();
Do you have a solution how can test the text on this popup?
Actually, it is not related to the web browser any more. You need to interact with it as a desktop window.
->If you want to click it using selenium, you can locate its coordinates and use click by coordinates using selenium.
->If you want to accept to download it, you can find a capability to accept downloading by default (except IE).
->If you want to check the text value, for sure you've to automate it as desktop not as a web.
I'm just trying to find out how to tell java to open a website and enter text (preferably a string value) into a text field
For example go to Google and search any text( it does not have to be user entered)
I realize that it wont actually open any browser or print anything from a website. I just need to know this basic part to build on for my program.
If you try to query to Google in your example and want to get the search result, you can use query string and read its html result
Figured it out . I had to use a combination of Selenium and HtmlUnit. My code is something like this
WebDriver driver = new HtmlUnitDriver();
driver.get("https://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Hello");
driver.quit();
We are testing a ASPNET MVC Application by using Selenium.
In the Webpage they are using a Jquery Date control Textbox datepicker/#icon-trigger
and that text box was in Disable mode
I am trying to send the values from selenium to webpage by using following code.
Driver.findElement(By.id("txtDOB")).sendKeys("10/10/1986");
But it was not working. it doesn't show any error.
and Now My question is how to send values to Disabled text box?
Can any one help me on this...?
Well you have two approaches here
Do it like a user would do and use the query date picker see here (untested)
Enable the text box and then set the field something like this:
WebElement textbox = driver.findElement(By.id("xxx"));
((JavascriptExecutor) driver).executeScript("arguments[0].enabled = true", textbox);
I would really recommend that you script this so that it uses the date picker, in the exact same way a user would have to pick a date, as the user is not allowed to type in their own date.
If really must work around this, then you could try forcing a value into the textbox using javascript:
IWebElement textbox = driver.findElement(By.id("txtDOB"));
((JavascriptExecutor)driver).executeScript("arguments[0].value='10/10/1986'", textbox);
i didn`t find any useful info about my problem. sorry if i repeat.
for example i want to click at the main page of http://www.bbc.com/ in the bottom of site link "Mobile site". in casual i do smth like this, to click on my button:
driver.getMouse(driver.findElement(By.Id("blq-footer-mobile"))).click();
but now i need to simulate the activity of user.
1. i need to scroll the page to bottom
2. need to move the cursor on link
3. click it
i realy tried all what i found in the internet, but everything wrong.
WebDriver simulates user interactions with web applications using native browser APIs. So as long as you are using pure WebDriver API, you are simulating natural user. You don't need to explicitly scroll, WebDriver would do that for you. If it's not scrolling then it is a bug and please report it accordingly. As for your question, here is the code that works.
WebDriver driver = new FirefoxDriver();
driver.get("http://www.bbc.com/");
WebElement element = driver.findElement(By.id("blq-footer-mobile"));
element.click();
The Mobile site link in the above website will just take u to UK website of BBC..
which means, a click on Mobile site link in http://www.bbc.com/ will actually lead you to http://www.bbc.co.uk/, where in the page remains same with just the URL changed..
if you really want to experiment on Mobile site link, use this URL : http://www.bbc.co.uk/
you can try the following code :
WebDriver driver = new FirefoxDriver();
driver.get("http://www.bbc.co.uk/");
new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.id("blq-footer-mobile"))).click();
this will wait for elements visibility and click on it,and this will take you to actual mobile site of BBC..