I am unable to locate this element with the class name. Below is the HTML code:
<a class="j-js-stream-options j-homenav-options jive-icon-med jive-icon-gear" title="Stream options" href="#"></a>
I tried to create an xpath using class and title both of them did the work in eclipse...ex:
//a[#title='Stream options']
//a[contains(#class,'j-js-stream-options j-homenav-options jive-icon-med jive-icon-gear')]
..
the None of the above options worked and I tried a few others too...Essentially I want to click on this element and do some action..I want to locate the randomly created xpath so that I can click on the element in the next run.
FYI: the element is a hidden element I need to click on some other element before this element appears. This is a dynamically created element whose expath changes all the time.
Any suggestions would be greatly appreciated...Thanks
Is the element you want to select in a separate iframe? If so, you need to switch to the correct iframe (driver.switchTo().frame("frame-id")) before firing the xpath selector.
Additionally, something to watch out for is that old versions of IE didn't have a native xpath library. See this answer for more details.
Related
I learn Selenium in Java and I'm struggling with little problem.
I'm working on handling dropdowns and to resolve my probelm I have to use Select class.
I wrote a selector:
#FindBy(css="#speed")
WebElement selectSpeed;
Then I wrote a method :
public SelectMenuPage selectRandomSpeed(){
getWaitForTheElement().untilElementIsPresentCss("#speed");
//webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(locator)));
Select select = new Select(selectSpeed);
select.selectByIndex(0);
return this;
}
The problem is that when I use Select class the code simply does not work and I receive:
org.openqa.selenium.ElementNotInteractableException: element not interactable:
Element is not currently visible and may not be manipulated
It works very well when, instead of using Select, I just put the selectors of all the wanted elements and just simply interact with them. Unfortunately, I have to use Select class.
Here is my DOM
As per the HTML, the html-select tag is having the style attribute set as display: none;.
Unless the element is visible within the HTML DOM Select() may not work properly.
Did anyone experience handling the element which is inside the #document section?
I had tried for absolute xpath, JavascriptExecutor, shadow, switchTo but still not able to locate the element.
the html structure as shown in the pic
html typing version
I'm able to locate the element by using switchTo method
driver.switchTo.frame(driver.findElement(By.tagName("object")));
driver.findElement(By.cssSelector("input[name='custId']")).sendKeys("customer123");
I am creating automation testscipt for a webapps using angular to develop frontend. There is a form with multiple input field inside a fieldset tag. I use Chrome DevTools to find xpath of the above input field but when run the script with my framework, webdriver cannot find the element with my xpath. Webdriver can click on the fieldset tag but cannot interact with any element inside the fieldset tag. I try debugging and put breakpoint at the step which input text to the input field but it doesn’t work. Please let me know what’s happen with the element inside the fieldset tag! Thanks a lot!
How can i click on this button with selenium ?
<a class="_42ft _4jy0 rfloat _ohf _4jy4 _517h _51sy" role="button" href="" ajaxify="/nux/wizard/step/?action=skip" rel="async-post" id="u_9_8">İleri</a>
Something I wish I would have figured out earlier was how to create my own advanced CSS selectors here is the page that taught me, it will work in all cases assuming your element is visible in the DOM.
https://www.smashingmagazine.com/2009/08/taming-advanced-css-selectors/
For your given element you could write this many ways
Generic form
tag[attribute='ATTRIBUTE_VALUE']
For your example
a[id='u_9_8']
or
a[class='_42ft _4jy0 rfloat _ohf _4jy4 _517h _51sy']
or
a[rel='async-post']
Now all these selectors will only be useful if the attribute is unique. But take a look at that article there are many tricks you can use to make CSS selectors work for you.
By using xpath with contains text you can click on the element(below is the answer)
driver.findElement(By.xpath("//a[contains(text(),'Ileri')]")).click();
Try it and let me know if it works for you
Try any of these below mentioned code.
Using id locator
driver.findElement(By.id("u_9_8")).click();
Using xpath locator
driver.findElement(By.xpath("//a[text()= 'İleri']").click();
Explanation:- Use text method along with <a>tag.
driver.findElement(By.xpath("//a[#role='button'][text()= 'İleri']").click();
Explanation:- Use role attribute and text method along with <a> tag.
Please add the wait conditions before you are going to click
Element clicking Via linkText :
webDriver.findElement(By.linkText("İleri")).click();
Element clicking Via id :
webDriver.findElement(By.id("u_9_8")).click();
Element clicking Via cssSelector :
1.webDriver.findElement(By.cssSelector("._42ft._4jy0.rfloat._ohf._4jy4._517h._51sy")).click();
2.webDriver.findElement(By.cssSelector("a[class='_42ft _4jy0 rfloat _ohf _4jy4 _517h _51sy']")).click();
Element clicking Via javaScript :
((JavascriptExecutor) driver).executeScript("arguments[0].click();", webElement);
Here you need to pass the element locator instead of webElement.
We can see ID attribute tag so we can use ID "u_9_8" to click on the button.
use the below code.
driver.findelement(By.id("u_9_8")).click();
I think you should be able to use the id
driver.findElement(By.id("u_9_8")).click();
Give it a shot
I'am trying to automate http://rose.99ats.com/careers.aspx
After clicking on "signup", I couldn't find the element Popup. I used getWindowHandle(), also used driver.swithchto(), but getting error. I can't find element.
Because it's in a new iframe, you need to use driver.switchTo().frame().
Here is a detailed answer on using switchTo(), in which you can't use name/id in your case, index should generally be avoided, so you may try locate the iframe element by css selector or xpath first, then switch to this WebElement.
WebElement popup = driver.findElement(By.cssSelector("iframe[src^='CareerSignUp.aspx']"));
driver.switchTo().frame(popup);
// or by index: driver.switchTo().frame(0);