How to make post on Facebook using Selenium Webdriver + Java?
This window. http://prntscr.com/i603dv
My code:
driver.findElement(By.xpath("//input[#id='email']")).sendKeys("me-email");
driver.findElement(By.xpath("//input[#id='pass']")).sendKeys("my-password");
driver.findElement(By.xpath("//label[#id='loginbutton']")).click();
//here I turn off notifications
driver.findElement(By.xpath("//a[#action='cancel']")).click();
Actions actions = new Actions(driver);
//with help of this code I can focus on window.
WebElement element = driver.findElement(By.xpath("(//span[#class=\"uiIconText _5qtp\"])[1]"));
actions.doubleClick(element);
//Here I want to post text, but it doesn't work.
driver.findElement(By.xpath("//div[#class=\"_1mf _1mj\"]")).sendKeys("Test");
Why it doesn't work? Then I press button Post but it doesn't work also.
The popup/window opens after double click . So you could try to switch to new popup using switch to window of webdriver. It should help .
Here is a link of simple webdriver test which switch window
http://learn-automation.com/handle-multiple-windows-in-selenium-webdriver/
Try to do the same for you .
If you have any questions let me know .
"_1mf _1mj " is a complex class. Selenium won't work on complex classes.
You can try Action chain - press "tab" button multiple times until you reach to "post"
Also, Facebook provides a drop down option after pressing tab button . You can choose from the drop down what you want to do., Using selenium.
Alternatively try mbasic version of FB.
Related
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.
How to handle the Modal window?Selenium webdriver , testNG with java
For example:
Load https://business.bell.ca/shop/small-business/
Click on Share Via email icon below the Facebook icon on right hand side.
Modal window is displayed
How to handle this modal window as i need to take the Screen shot of that modal window?
There isnt any modal window. If you are trying to click on Like, its under an iframe. To switch to it perform:
driver.findElement(By.cssSelector(".fui-icon.fui-icon-facebook"))
.click();
driver.switchTo().frame(
driver.findElement(By.xpath("//iframe[#title='facebook']")));
driver.findElement(By.xpath("//span[.='Like']")).click();
and to switch to facebook window that follows do:
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle);
}
EDIT:
Sorry it was my mistake that i took didn't got what you tried to ask. As a workaround if you want to interact with the modal dialog you could use by initially waiting for the modal-dialog to appear, and since its under top-window scope only, you can interact with the fields using xpath or css, whichever you prefer. A sample code for it with xpath would be:
driver.findElement(By.id("shareemail")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions
.visibilityOfElementLocated(By
.xpath("//*[#id='emaillightboxmodaljs']")));
driver.findElement(
By.xpath(".//*[#id='ui-id-3']/div/fieldset/div[1]/div[1]/input"))
.sendKeys("acd");
I'm facing an issue writing a Selenium program using Java.
I'm trying to click the following link :
חפש
by using the following code:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://mapi.gov.il/Pages/LotAddressLocator.aspx");
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
WebElement element = driver.findElement(By.id("AddressInput"));
element.sendKeys("הנגיד 16");
WebElement button = driver.findElement(By.id("helkaSubmit"));
button.click();
String pageSource=driver.getPageSource();
System.out.println(pageSource);
But it doesn't seems like the button was clicked at all, since the page content which must change after clicking the link, does not change at all.
I need to find a way to check whether the link was clicked at all, or to find why it was not clicked.
Can anyone point me to the solution ?
EDIT:
Using executor.executeScript("document.getElementById('helkaSubmit').href='http://www.google.co.il';");
executor.executeScript("document.getElementById('helkaSubmit').click();");
Worked just fine, so javascript is enabled and clicking is executed, but for some reason the original code does nothing.
try this,
driver.findElement(By.id("helkaSubmit")).click();
I am trying to select text which is already present on the browser.
I want to select that particular text and perform right click operation on it.
However, the page on the browser has disabled right click.
How can I select text in such situation?
Using a normal web browser without Selenium the only workaround that I can think about is to disable javascript to stop the script that prevents you from right clicking. So it should also work with a browser controlled by Selenium Webdriver.
I don't know if it will be OK for you because your website may be relying on javascript for essential features.
However if you don't need Javascript for your Selenium test you can try the following when you launch your driver :
FirefoxProfile p = new FirefoxProfile();
p.setPreference("javascript.enabled", false);
driver = new FirefoxDriver(p);
I assume that you already know how to perform a right click because your question was only about dealing with the problem preventing you from doing this right click. But if not, you can also refer to this answer :
Select an Option from the Right-Click Menu in Selenium Webdriver - Java
Edit:
I'm sorry I really thought you could use Selenium actions to select the text you want but after some tests I didn't manage to perform a click and drag to select a text. The only thing that works for me in Chrome or Firefox is the following. It looks for a <p>which contains some text and then perform a double click to select a word.
driver.get("http://en.wikipedia.org/wiki/Java_(programming_language)");
WebElement text = driver.findElement(By.xpath("//p[contains(text(),'Java is')]"));
Actions select = new Actions(driver);
select.doubleClick(text).build().perform();
However it only highlighs one word in the html element that contains your text, so it's not really convenient.
I've also tried to do Ctrl+F and type the text so that the web browser automatically select it but the browser doesn't do anything when executing :
Actions search = new Actions(driver);
search .sendKeys(Keys.chord(Keys.CONTROL,"+f")).sendKeys("Java is").build().perform();
It seems that Selenium can only send keys events to the html elements and not to the browser (in the case of ctrl+F).
I don't really see a solution for now, let's see if someone else can find a workaround. It's an interesting issue, it would also be useful for me to select a text the way you described
Move to middle of the element
Actions builder = new Actions(webDriverObject);
builder.moveToElement(element).build().perform();
Move to starting of element, click and hold, move to end
Integer width = element.getSize().getWidth();
Actions newBuilder = new Actions(webDriverObject);
newBuilder.moveByOffset(width/2,0).clickAndHold.moveByOffset(width,0).release().build().perform();
I'm trying to test a tool tip option for mouseover activity on a web image element. How to make sure whether the tool tip is being displayed or not ? here the problem is, in Mozilla, multi-line tool tip will be displayed as single line only. Can anyone help me out on how to test these things ?
Try this ..
Actions builder = new Actions(driver);
WebElement Element1 = driver.findElement(By.xpath("//*[#id='badge_people']/li[1]/img"));
Thread.sleep(6000);
builder.moveToElement(Element1).perform();
System.out.println("User Name :"+ driver.findElement(By.xpath("//[#id='badge_people']/div/div[2]")).getText());
builder.moveToElement(Element1).release().perform();