My aim is to automate next Slide of SlideShare present on the web page using selenium.
How to next/previous SlideShare with Java code for Selenium?
WebElement slide = getDriver().findElement(By.id("slidesharePlayer")); // use the id of the searchbar to find it
Thread.sleep(2000);
slide.sendKeys("next()");
this fails to move next slide
any idea how to move next slide ?
new Actions(getDriver())
.sendKeys(getDriver().findElement(By.id("slidesharePlayer")), Keys.ARROW_RIGHT)
.build().perform();
by press right key from key bord ...
You are doing it all wrong.
Slideshare doesn't have any element with id slidesharePlayer.
Using Thread.sleep is not a good idea.
sendKeys() will send the keys next() to the element slide.
You can do something like..
getDriver().findElement(By.xpath("//a[contains(#title, 'Next Slide')]").click();
which clicks on an a element with title property set to "Next Slide" .
Related
I'm building a final project and I got stuck in a problem.
Website: trello.com
I have a page that contains buttons with boards that i have created and button to create a board.
I try to store all these buttons, then locate them by text and click on them.
The problem is this, I manage to access all the buttons, but can not click on them
For example: there are three buttons (see picture), the third button is "create new board".
According to the console, I can import his text, but can not click it (after command click nothing happens).
I'm noob, so I hope I've listed everything, and I'll be happy to help.
This is my code:
There is the pic of the trello page with the boards.
https://ibb.co/kmV6V4n
private By mainBoardSelectorList = By.xpath("//*[#id=\"content\"]/div/div[2]/div/div/div/div/div[2]/div/div/div/ul");
public WebElement getMainBoardSelectorList() {
return driver.findElement(mainBoardSelectorList);
}
#Test
public void getAllBoardsAndClick(){
methodsManager.logIn();
BoardsPage boardsPage = new BoardsPage(driver);
System.out.println(boardsPage.getMainBoardSelectorList().getText());
WebElement el = boardsPage.getMainBoardSelectorList();
if (el.getText().contains("Create new board")){
el.click();
}
}
Jul 11, 2019 12:42:26 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
hj,
Untitled board
Create new board
Double check your selector as it might match something which is not clickable, or clickable but resulting into nothing. Use browser developer tools to find out what are the matches as you might get false positive results
It is possible to locate element by partial link text like:
driver.findElement(By.partialLinkText("Create new board"));
There is findElements() function which returns the List of WebElements which is more suitable for your use case
Be aware that once you click the link and navigate away from the page all the WebElements will be invalidated and you will get StaleElementReferenceException so either consider re-do the "find" once you're back or better go for Page Object Model design pattern which implements lazy initialization tactic when it comes to locating the elements.
You need to click on li tags not ul
You can change your function getMainBoardSelectorList() to return
List<WebElement> instead of WebElement .
public List<WebElement> getMainBoardSelectorList() {
return driver.findElement(mainBoardSelectorList).findElements(By.tagName("li")));
}
Now your method returns all li elements(boards) that you need.
I think "Create new board" is always the last one so you can do
List<WebElement> els = boardsPage.getMainBoardSelectorList();
els.get(els.size() - 1).click());
Don't forget to handle exceptions
Step 1: Navigate and Login
driver.get("https://trello.com/login");
Thread.sleep(1000);
driver.findElement(By.xpath("//*[#id='user']")).sendKeys("paste your username here");
driver.findElement(By.xpath("//*[#id='password']")).sendKeys("paste your password here");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id='login']")).click();
Thread.sleep(3000);
Step 2: To Click on First Board
Here in xpath #title is your Board name so create xpath according this, for me test is First board name
driver.findElement(By.xpath(".//div[#title='test']/descendant::div")).click();
Thread.sleep(5000);
driver.navigate().back();
Thread.sleep(3000);
Step 3 : To Click on Second Board
Here in xpath #title is your Board name so create xpath according this, for me test1 is Second board name
driver.findElement(By.xpath(".//div[#title='test1']/descendant::div")).click();
Thread.sleep(5000);
driver.navigate().back();
Thread.sleep(3000);
Step 3 : To Click on Third Board
For Click on Create new board manage xpath from class name and click on it.
driver.findElement(By.xpath(".//div[#class='board-tile mod-add']/descendant::span")).click();
by this you can click all your board one by one. You can create function for manage xpath dynamically for board.
I need to click on an element inside a Dropdown container. I've tried several searchs but I haven't been able to find the correct solution. The select method doesn't work, and I still don't know how to work with Selectors when there's no ID, Name or Class related to it. Here's the HTML code:
Account<span class="caret"></span>
<div class="account-dropdown__container">
<ul>
<li>Account</li>
<li>Invite Friends</li>
<li>Zola Store Credit</li>
<li>Registry Settings</li>
<li>Orders You've Placed</li>
<li><a>Log out</a></li>
</ul>
</div>
The first piece of code is a button, but if I put my mouse over it, it will show the Dropdown container that I am talking about. If I put my mouse over it without clicking, it will show the list of the Dropdown Container. (And I would also like to know how to hover an element to show the list without clicking it, because its hidden).
My question is, then: how can I click on Registry Settings?
It doesn't have an ID, nor a class (although it is inside the class account-dropdown__container). I think I can use By.name("Registry Settings"), but since is not visible unless the Dropdown list is open, it won't click and it will show Css Selector not found error. Care to help? Thanks!
Also, I am using Cucumber + Selenium + Java in IntelliJ IDEA, the synthaxis changes just a bit, but it is still different from the codes I tend to find in this forum. Hence, why I am asking for a specific solution to my problem.
You have to make the dropdown visible first.
As in Selenium you can't just hover an element, you will have to do it all in one go.
Check this: How to perform mouseover function in Selenium WebDriver using Java?
Actions action = new Actions(webdriver);
WebElement button = webdriver.findElement(By.class("account-link"));
action.moveToElement(button).moveToElement(webdriver.findElement(By.linkText("Registry Settings")).click().build().perform();
You may have to wait in between for the dropdown to appear. I have not tested the code, you will probably have to fix it before it works.
As you have mentioned when you put your mouse over to a button, it will show the Dropdown container.
Same can be automated with the help of selenium like this : (I am assuming account is a button )
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.linkText("Account"))).build().perform();
Now your drop-down is expanded or visible in UI, and you want to click on Registry Settings . Since your drop down is not made using Select options tags which are available in HTML. You can't use Select class from Selenium.
You will have to store every elements which are present in drop down to a list. and then based on some condition , you can click on your desire element.
Code:
List<WebElement> options = driver.findElements(By.cssSelector("div.account-dropdown__container ul li"));
for(WebElement option : options) {
if(option.getText().trim().contains("Registry Settings")) {
option.click();
}
}
Hope this will help.
I want to perform click action on a button present under .svg layout using Selenium (Java bindings).
For example, I want to click on the button element, but every time I try to find an element by xpath, I get exception `enable to locate element
I read that with Selenium its tricky to click on element present under the .svg.
Is there anybody who knows a solution because, I haven't found a suitable solution on the net by myself.
Find below HTML code look likes this way:
My code:
List <WebElement> frame1=driver.findElements(By.xpath("//iframe[contains(#id,'-06636000002Pb2L')]"));
System.out.println(frame1.size());
System.out.println(frame1.get(0).getAttribute("title"));
driver.switchTo().frame(0);
ElementaryOperations.Sleep(3000);
System.out.println("New relation frame found");
driver.findElement(By.cssSelector("#newrel")).click();
After switching to frame successfully, I am not able to click on the element present under the SVG layout. Please refer to the attached screen shot(link)
this is how you should be able to identify SVG node and then sub nodes of that.
//*[local-name() = 'svg']
use this code
driver.findElement(By.id("rfb")).click();
try using class attribute of the button using CSS Selectors:
driver.findElement(By.cssSelector(".btn.btn-primary")).click()
i have some problems to get the right element to perform a click.
I use selenium.
I want to click on the Log In "Button" on this page https://campus.uni-stuttgart.de/cusonline/webnav.ini
Maybe sb could help me.
Thanks
Try this code. The login button is available under a frame. so it is necessary to switch to that frame in order to access the element.
driver.get("https://campus.uni-stuttgart.de/cusonline/webnav.ini");
driver.switchTo().frame(driver.findElement(By.xpath("//*[#name='menue']")));
driver.findElement(By.cssSelector("#menue_frame_key_icon > img")).click();
driver.switchTo().defaultContent();
It appear the login button id is "menue_frame_key_icon".
So this should be:
driver.findElement(By.id("menue_frame_key_icon")).click();
You could alternately try the child element of that id, which can be done multiple ways. This will work though:
driver.findElement(By.cssSelector("#menue_frame_key_icon > img")).click();
Is there any way to scroll page to current webElement using selenium for Java?
I would like to click on element but when the element is down or up it clicks on another place - so I want to scroll page to current element.
I searched but havent found any solution.
Any help - Advance Thanks !
You need look up the id and fire click event on that id.
I want to click on next button on my page whose id="nextButton"
In the page object here is how i declared. That way you dont need worry about where the position is
Eg:
#FindBy(how = How.ID, using = "nextButton")
private WebElement next;
More info at
http://reddymails.blogspot.com/2011/09/selenium-2-or-webdriver-for-automation.html