I am not able to select and click on an element which is located in footer.
Below is the code
I tried getting right XPath using Chrome console. Below are the code that I have tried. It is not highlighting the element. Please suggest if why it is not locating.
driver.findElement(By.xpath("li#btnEnableEditing.LoginOkButtonFooter")).click();
And I have also tried using move to as below
a.moveToElement(driver.findElement(By.xpath("li#btnEnableEditing.LoginOkButtonFooter"))).click().perform();
a.moveToElement(driver.findElement(By.xpath("//*#id='btnEnableEditing']"))).click().perform();
The xpath you are using is invalid. The first two code lines are actually used in cssSelector
driver.findElement(By.cssSelector("li#btnEnableEditing.LoginOkButtonFooter")).click();
Or just
driver.findElement(By.cssSelector("#btnEnableEditing")).click();
Or using By.id
driver.findElement(By.id("btnEnableEditing")).click();
And you are missing square brackets in the last one
driver.findElement(By.xpath("//*[#id='btnEnableEditing']")).click();
Related
So I am trying to locate Account Activity from below lines of codes using contains(text(), 'value') but I am not able to do so. I tried to remove   using different stackoverflow answers but none of them work. Can someone please help me out here?
WebPage:
Mylines of code:
Thanks.
Try the following xpath:
//span[contains(text(),'Account Activity')]
From the web page structure you presented here it looks like the Account Activity and Current Day Balances are not inside the input elements but they are all inside the small element which is inside span so I'd prefer basing on span element containing all them.
Try this by normalizing the spaces:
driver.find_element_by_xpath("//input[normalize-space(text()) = 'Account Activity']").click()
If that doesn't work maybe try another approach:
driver.find_element_by_name("irOperations[0]").click()
I have text located in these two locations:
The elements I want the text from:
//*[#id="RoleSetUpNewForm"]/div/table/tbody/tr[1]/td[2]/table[2]/tbody/tr/td/div[1]/table[3]/tbody/tr[2]/td/table[1]/tbody/tr/td[2]/table[1]/tbody/tr/td/label
The elements that I do not want the text from:
//*[#id="home"]/div[16]/form/div/table/tbody/tr[1]/td[1]/table/tbody/tr[18]/td[3]/div/a
This xpath statement when executed in Selenium keeps giving me both the elements I want, AND the elements I do not want:
driver.findElements(By.xpath("//td[#class='level3TD']/label"));
Clearly the xpath above does not reference the location that I do not want the text from, but I am getting the text elements from it returned..
I am just baffled. Any ideas? Is there something I need to do with my selenium xpath query to stop the text from the path ending in /div/a from coming back?
There is no need to manually write XPath's.
Open the dev console by pressing F12 (assuming you are on a Windows machine).
Now find the node that you want, right click on it and click "Copy". Now you can copy the relative XPath, Full XPath, JS Path or Selector. In your case you look like you want the Full XPath.
This can be done on all machines, in all browsers.
I figured this out, there were duplicate label text on the page that made me think the xpath was pulling from the wrong location. Lets close this.
I am using Selenium to build a test automation where the html is in an iFrame, I was able to find online the lines of code to activate the iFrame, click on a link, and press a button and they are working fine -see following lines:
driver.SwitchTo().Frame("06634000000BVL6");
driver.FindElement(By.LinkText("Loan Details R1")).Click();
driver.FindElement(By.XPath("//button[contains(.,'Edit')]")).Click();
I needed to input a text within a textBox in that iFrame, but I couldn't handle the ID or the Class, below is the HTML for the input:
Any thoughts ?
Thanks for your help
I can't comment yet, so this will be part answer, part comment.
Based on what you have posted, it looks like you may not be in the correct iframe and we don't have enough of the code from the webpage to tell if there is an additional iframe.
I'd also like to see the code you are using to write text to the field, you may have an issue there.
If you don't and the only issue you have is the selector then try the following. Go get the developer version of firefox. Navigate to your webpage in firefox. Inspect the element where you want to write text to. Once you are in the inspection screen, there is a path bar that can scroll left and right at the bottom of the screen. Check that to confirm that there is only the one iframe you mentioned and that you are in the correct iframe. If that is the issue, you should be good to go, you're code above works for switching between frames. If you are in the right iframe, then try a different method of finding the element for the text box. I have had the most success with hard to find elements by using the cssselector. To get the cssselector for the element right click on it, navigate to copy and then cssselector. From there your code should look like this (using c#):
driver.FindElement(By.CssSelector("INSERT CSS SELECTOR HERE")).SendKeys("Text");
This is what the error displays when I use the xpath
What command on the selenium webdriver would I use to click a text which has a xpath of
html/body/div[1]/div/div/div[2]/div[2]/div[2]/a
I tried using
driver.findElement(By.xpath("html/body/div[1]/div/div/div[2]/div[2]/div[2]/a")).click();
but still doesn't work... any suggestions?
Your xpath is incorrect. You are trying to hit an absolute path with html/body/div[1]/div/div/div[2]/div[2]/div[2]/a. You are missing a / so instead it should be /html/body/div[1]/div/div/div[2]/div[2]/div[2]/a
try:
driver.findElement(By.xpath("/html/body/div[1]/div/div/div[2]/div[2]/div[2]/a")).click();
I have seen similar issues when the element to be located was in a separate iframe.
Using FirePath or source html, check if there are any iframes and if yes, use
driver.switchTo().frame("framename")
and then use
driver.findElement(By.xpath("/html/body/div1/div/div/div[2]/div[2]/div[2]/a")).click();
What about just using By.linkText() or By.partialLinkText() instead of XPath? Using XPath in this way is "easy" but very fragile I would recommend against it.
driver.findElement(By.partialLinkText("EARN up to "));
You can, of course, edit the partial link text to be more or less specific depending on what you are looking for and how unique the text is on the page.
Since that didn't work, let's try a different approach. Let's find all the links in the table you have pictured above. The code below will grab the A tags in the table and then click the first one. My guess from the picture is that the text contained in the link will likely change so having a more flexible way to find the links is better than using the link text. See if the below works.
List<WebElement> links = driver.findElements(By.cssSelector("div.data-block-sub-popular-offers > div.row-heading > a"));
links[0].click();
Instead of using absolute xpath which is not reliable way to identify an element, you can try this: //input[#id='partnerId']/following-sibling::a. It finds an element with unique id and then locates nearest sibling having tag a
just use xpath below:
driver.findElement(By.xpath("//div[#class='row-40percent']/a[contains(text(),'Earn upto 2.5%')]").click();
how do I get the xpath or css or ANYthing to click this ok button??? Problem is these ids and other attributes have tags that are changed every time a user goes to this particular page
--ea3b2e21-3847-47de-860c-3596695fbb35-- so i don't know what to do
Ok
All you can do here is try and find some part of the element that does not change. If you can add some sample html it would help.
Have you read the
docs for dynamic elements?