Selenium web driver cannot recognize a link text - selenium-webdriver

in one of the web app that I am automating, I find that I came across to some elements that have no ID or class or anything associated, or associated dynamically and won't be able to capture, therefore I have to use link text, for example, "Canada", and then when I do
driver.FindElements(By.LinkText("Canada")).Count > 0 ,
I won't get a "True" although "Canada" is right there. Does anybody came across this before and have any idea why it is?
Thank you!

Use
driver.switchTo().frame("Your LinkText Frame Name");
driver.FindElements(By.LinkText("Canada")).Count > 0 ;
and try.
I think it may work.

Are you sure "Canada" is indeed in a <a> tag ? By.LinkText is meant to search for anchor text
You can certainly create a XPath to search By.xpath. Something like "//*[contains(text(),'Canada')]" (this is the only xpath I can give you without knowing your HTML structure)

Related

How to locate element based on text()/contains criteria in Cypress.io

I need to locate an element/ verify presense of an element, based on the Text inside element, using something like:
//div[contains(text(),'<My intended text>')]
As Cypress.io do not support the XPATh yet, then how to locate it using alternate locators.
There seems to be lot of discussions around cssselectors :contains & when tried div:contains('<My intended text>') it failed to locate the element.
Given the fact that both XPATH & CSSLocators have good performance on modern browsers.
Kindly advise. Thanks
so you are looking for the parent which holds 'My intended text'?
You can do so by using:
cy.contains('My intended text')
and that's how you selected the element. Now you can use for example .click() to click on the element which holds 'My intended text'

Accessing compound classes in Selenium on Google search results page

I am trying to access the People also ask panel content on the Google search results page for a given search and to extract the question and answer text of the presented questions. However, when I try to access the compound class, with browser.find_elements_by_class_name("_Tgc _s8w _y9e")I get an error and I've tried to fix it by using browser.find_elements_by_class_name("._Tgc._s8w._y9e") but then I get no results? I can't find out how else to access the HTML text, any help is much appreciated! Thank you!
Figured it out, for anyone else who comes across this question:
browser.find_elements_by_xpath("//*[#class='_Tgc _s8w _y9e']")
by using xpath you can reference compound classes

how to find the Xpath for below given check box

enter image description here
Please tell me how to get the xpath for check box.
If you are using Chrome browser - one easy way you can use:
Open the Inspect (or just click the F12 key)
Mark the element you need and right click on it (or just right click on the object (the check box) you are looking for)
Choose Copy ---> Copy Xpath
I think the tshirt option is not public yet, did not get it in your site.I tried with shirts, looks like same dev pattern to me, let me know if the solution does not work.
<input id="Classic" class="facetChkBox" type="checkbox" value="brickstyletype:Classic" name=""/>
<label for="Classic"/>
This is the background html code.
As you already know, this is not the classic checkbox html code, so we need to create a xpath for this as shown below
driver.findElement(By.xpath(".//label[#for='Classic']"))
from the point of code reusablity I would suggest a method like this:
public void clickOnCheckbox(String checkbox){
driver.findElement(By.xpath(".//label[#for='"+checkbox+"']")).click();
}
and call it using
clickOnCheckbox("Blousons");
In this way you can use the same code to click on different check boxes, and create a clean code.
to relate more to what I am saying you can go the url
https://www.ajio.com/women-shirts/c/830316016

DotNetNuke parse HTML before display

Could anyone tell me if there's some way of "hooking in" to DotNetNuke so that I can, for example, search and replace text for ALL HTML modules on the site?
e.g. if I use an HTML editor and enter the text {{replace_me}}, then I could have some code that detects "{{replace_me}}" every time a page is rendered and replace it with something else.
Please note that this is a simple example - there may be other ways of "replacing" text - however the actual use case we have is very specific and there will be some significant processing to decide what to replace :) - so whatever solution we implement should basically be:
Get HTML from DB -> Process it however we wish in full C# -> Deliver the modified string.
Thanks!
I believe you can do this with the use of an HTTPModule. Ifinity.com.au used to sell a module that did this, looks like you might be able to download it now for free (maybe?) at http://www.ifinity.com.au/Products/Inline_Link_Master/Product_Details

Find Element using Selenium Webdriver

I am trying to find an element in the website that i am trying to automate but am unable to figure out how to fetch a particular element. I have provided the html below. Please provide some inputs. Thanks.
< div id="Troy_combine" class="sign_in_flow sign_in_flow_overlay troy_overlay epc_modal big_dialog modal_display" > < h3 class="migration"> Welcome back.< /h3>< h3 class="normal">Welcome to Disneyland< / h3>< p class="migration">It looks like you have a account that use the same address and password. Let’s combine them into a single account to make it easier to access both services.< /p>
Note: There are multiple "migration" classes. How will it know which one to pick up??
I am trying to fetch the text shown in Italics. Help required
Selenium Webdriver with Java
I would use a cssSelector like so:
String itext = driver
.findElement( By.cssSelector("div#Troy_combine p.migration")).getText();
Selecting via classes and IDs are always the easiest and most reliable. Do a By.className("migration").
findElement(By.cssSelector("div.migration")).getText();
I think you could select it by ID as well.

Resources