I'm trying to right-click on a link and use the keys arrow-down and enter to open a new tab.
Problem: No error displayed during execution. The link is identified and a right-click is made on it. however, the code is not performing the down-arrow and entering the action. Can't seem to figure out why.
Can somebody help?
Code:
a.moveToElement(subfooterdriver.findElements(By.tagName("a")).get(1)).contextClick().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
a - obj to action class,
subfooterdriver - is a frame consisting of 5 links
Updated:
I was able to overcome the issue with the following code but I want to understand what went wrong with the first code.
String clickonlink=Keys.chord(Keys.COMMAND,Keys.ENTER);
subfooterdriver.findElements(By.tagName("a")).get(i).sendKeys(clickonlink);
You can get the link inside this hyper text then open it in new tab as following :
//element locatore
WebElement link =driver.findElement(By.tagName("a"));
//Get Required URL
String url = link.getAttribute("href");
Related
I'm trying to create a link (href) that open itself in a new page. Should be "simple".
That's the focus code:
if (propertybox.getValue(CandidatoLink.LINK) != null) {
Anchor anchor = new Anchor(propertybox.getValue(CandidatoLink.LINK),
propertybox.getValue(CandidatoLink.LINK));
anchor.setTarget("_blank");
return anchor;
}
This is to get the link from the database, like "www.google.com":
propertybox.getValue(CandidatoLink.LINK));
This is to get the link opening in a new tab of the browser:
anchor.setTarget("_blank");
It works all just fine: I can get the link opened in a new tab. The only problem is that the system think that's an intern page of the website and sees it as a Route! That's the problem. It will open a new tab with this link: http://localhost:8080/www.google.com
I can't remove the first part (http://localhost:8080/). Can someone help me?
I use Java 11.0.15, Vaadin 14 (Maven/Spring Boot) and my IDE is Eclipse 2022-06 (4.24.0).
I am trying to put username and password to pop up window. The trouble is that this is some kind of modal or some external window where I can´t find any xpath, id etc... element how to identify this fields. I have came through all topics regarding this but non of them helped me in Java for cucumber/selenium.
Using "https://username:password#wedomain.cz/" doesn´t work.
Using code like this:
WebElement email_id = driver.findElement(By.linkText("Uživatelské
jméno"));
email_id.sendKeys("XXX");
WebElement password_id = driver.findElement(By.linkText("Heslo"));
password_id.sendKeys("xxx");
Thread.sleep(5000);
WebElement sign = driver.findElement(By.linkText("Přihlaste se"));
sign.click();
Doesn´t work. I must also say that domain I go to is different from domain I see on security pop up window.
SOLUTION - need to be done with robot class or another automation library.
https://www.guru99.com/using-robot-api-selenium.html
Closing question.
I'm trying to write code to automatically DM people on Instagram. Im stuck on getting the code to click on the DM button.
In UIautomatorviewer, there is no text or a resource-id, so I tried using the class.
When I run the code it doesn't click on the right thing. It clicks on the button NEXT to it.
Here is the code -
By path2 = By.xpath("//android.widget.ImageView[#index='3']");
driver.findElement(path2).click();
Thread.sleep(5000);
Can anyone help? I'm new to this so i'm not very experienced.
Because I can not see the entire XML I can not really tell what you did wrong but probably your xpath is not correct.
With UIAutomatorViewer you can save the XML and then you can test your xpath on it. Either with XMLSpy or an online tool like https://www.freeformatter.com/xpath-tester.html.
Probably there are more android.widget.ImageView with index = 3 and I think appium selects the first one? So you could change your xpath to a more unique one like:
//android.widget.FrameLayout//android.widget.LinearLayout//android.widget.ImageView[#index='3']"
Based on UIAutomator Viewer screen you can also use content-desc as shown below
By path2 = By.xpath("//android.widget.ImageView[contains(#content-desc,'Message')]");
driver.findElement(path2).click();
I know one can find similar question,but no one gave an alternate solution.Please bear with me.
After some research I realized it is not possible to automate contextClick in Chrome browser.For ex:
If I need to perform below code and browser has to be Chrome-
driver.get("https://www.google.com");
Actions ac= new Actions(driver);
ac.moveToElement(driver.findElement(By.id("hplogo"))).contextClick().sendKeys(Keys.ARROW_DOWN).build().perform();
It would be helpful if I can get an alternative to using contextClick options.
Thanks
On my chrome browser, contextClick is working fine. Try below line of code, it may resolve your problem.
ac.moveToElement(driver.findElement(By.id("hplogo"))).contextClick().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
Are you trying to do context click only, then
Actions conClick=new Actions(driver);
//i am expecting you are try to perform right click id = hplogo
conClick.contextClick(driver.findElement(By.id("hplogo"))).build().perform();
// if you want to select or click any option in this context menu
// go for click with specific location, no need of keys
// if required use sleep before click
driver.findElement(By.id("required location")).click();
if above click after context click is not working as expected, then you can also try below way
Actions conClick1=new Actions(driver);
//i am expecting you are try to perform right click id = hplogo
//after context click moving to 25 vertically, may be second option in context menu and clicking
conClick1.contextClick(driver.findElement(By.id("hplogo"))).moveByOffset(5, 25).click().build().perform();
Thank You,
Murali
I'm using the selenium RC driver for JUnit testing my application. Here is the relevant code I am trying to write. It checks that if the user clicks the link, they are taken to the right place.
selenium.click("//td[#id='myLink']/a");
String myURL = selenium.getLocation();
However, when the webdriver simulates a "click," it instead opens up a new window. So now I have the first window open, and the page that I wanted to navigate to is open in a seperate window. Now, when I try to get the URL, selenium grabs the first URL, so it fails the test case. How can I make the page open in the same window? Or, alternatively, how can I get selenium to check the URL of the new window?
EDIT: Should also mention, both my first and second window have the same title, so I don't think I can use selenium.SelectWindow(Title); for this.
Well, with selenium RC being as fickle as it is, I found a work-around for this problem. Here is the brief overview of how I changed my code:
String targetURL = selenium.getAttribute("//td[#id='myLink']/a#href");
selenium.openWindow(targetURL, "myNewWindow");
Thread.sleep(3000); //wait a few seconds for my page to load
selenium.selectWindow("myNewWindow");
selenium.getLocation();
//do my checks
selenium.selectWindow("originalWindowName");
So I retrieve the href myself, open the window using the retrieved URL and with my own custom name. I then switch the context of the driver to the new window and perform my checks. Once I am done, I switch my context back to the original window, and continue with my tests.