I am using Selenium with AgGrid (https://www.ag-grid.com/example.php)
I am trying to select the In Range option from the Total Winnings drop-down using the code below, I was wondering if there is a better way to repeat the sendKeys(Keys.ARROW_DOWN) instead of mentioning it again and again in a chain i.e. something like sendKeys(Keys.ARROW_DOWN).perform(6) (to be honest I didn't find anything in the API).
System.out.println("Select the Column");
driver.findElement(By.xpath("//div[#class='ag-header-cell ag-focus-managed'][#aria-colindex='10']//span")).click();
driver.findElement(By.xpath("//div[#class='ag-wrapper ag-picker-field-wrapper']")).click();
Actions actionObject = new Actions(driver);
actionObject.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform();
The above code is working and does perform the action however, just wondering if there's a better way to code this.
When the popup is rendered, you can rely on the role attribute of that popup, which is 'option'.
You can use this XPath query to select options inside the filter options popup:
let selectOptionQuery = '//div[#role="option" and contains(.,"In range")]';
I've created a simple example which selects the 'In range' option at the click of a button: https://plnkr.co/edit/S7A4EguRWmTjjl7g?preview
Related
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 have this strange issue. I have one Select drop-down list, with empty option selected in the beginning, and try to pick one option from it:
#FindBy(how=How.XPATH, using=".//select[#name='kontakt_l_user_id']")
WebElement przyjecie_select;
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//select[#name='kontakt_l_user_id']")));
przyjecie_select.click();
Select sel = new Select(przyjecie_select);
wait.until(ExpectedConditions.visibilityOfNestedElementsLocatedBy(przyjecie_select, By.xpath("//option[#value='2112']")));
sel.selectByValue("2112");
While the test is running, I can see, that this select drop-down is clicked, the desired option with value "2112" is found, because it is highlighted, but it is not picked and that empty option is still visible.
I tried many things, but the result is the same. I even add:
przyjecie_select.click();
Select sel = new Select(przyjecie_select);
wait.until(ExpectedConditions.visibilityOfNestedElementsLocatedBy(przyjecie_select, By.xpath("//option[#value='2112']")));
sel.selectByValue("2112");
but that also doesn't work. I'm using 2.53.
You are my only hope!
Ok, I found the solution, which was is pretty simple.
I used the .click() method on the Select, which was bad. Select automatically find element and click on it, so double click makes the computer confuse. It should look like that:
Select sel = new Select(przyjecie_select);
sel.selectByValue("2420");
instead of:
przyjecie_select.click();
Select sel = new Select(przyjecie_select);
sel.selectByValue("2420");
without attempting to click that Select element at first.
I am using Winium + Java for automation testing of Windows application, and trying to access tool bar menu.
When I tried to detect elements using UI Automation Verify, I couldn't see child elements under tool bar element like below screenshot.
enter image description here
But my tool bar definitely has sub menu items like screenshot and I need to access them.
enter image description here
I tried below java code, but it didn't work
WebElement el = driver.findElement(By.id('59398'));
el.click();
WebElement child = el.findElement(By.name('Start'));
child.click();
when I tried
driver.findElement(By.name"Start').click();
it clicked my windows start menu, not my application's menu.
Is there any way to access items under this tool bar?
You can try use another UI Inspector
eg. UI SPY or Inspector.exe
Probably your ID is not a AutomationID (process id?)
You should find a main window (parent of your app) (Example for calc) and get a parameter like AutomationId, ClassName or Name
I see this is MFC application, and this is an app side MFC library problem. If you hover mouse over toolbar button using Inspect.exe, the info is available but you can't reach this button from the hierarchy (the buttons have no parent somehow). Possible workaround involves combined Win32 API and UI Automation approach:
get button rectangle using Win32 API (but there is no text).
use ElementFromPoint method of UI Automation API and get actual texts to choose the right button.
P.S. My suggestion is applicable for Java + Winium in theory. But I can't estimate the complexity because I'm not a Java expert. So below is Python solution.
We have plans to implemented this mixed way in pywinauto. See issue #413. It contains Python code sample how to do that. We've had no chance to integrate it yet.
from ctypes.wintypes import tagPOINT
import pywinauto
app = pywinauto.Application().start(r'.\apps\MFC_samples\RebarTest.exe')
menu_bar = app.RebarTest.MenuBar.wrapper_object()
point = menu_bar.button(0).rectangle().mid_point()
point = menu_bar.client_to_screen(point)
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(point[0], point[1]))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
print(element.name)
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