Catching data attributes in testcafe - testing

I have a data attribute div which Testcafe doesn't seem to find
<input autofocus="autofocus" placeholder="Isikukood" data-v-0a9dbb1c="" data-t-id="Login_isikukood">
I tried this
input[data-t-id="Login_Isikukood"]
but without results. Any ideas?

For anyone interested, this worked [data-t-id="Login_isikukood"]

Related

Why I can't find any selector with Xpath using two classes

I got a html page like this
<li class="class1 class2"></li>
but I try to find this selector by using
response.xpath('//li[#class="class1 class2"]')
I always got None.
I also try to run this code:
response.xpath('//li[#class="class1"]')
response.xpath('//li[#class="class1 class2"]')
Both return None
Who can tell me what's wrong?
Maybe I resolved but I don't understand. I found a phenomenon that I use DevTools on Chrome, that shows like this <li class="class1 class2"><\li>. But I use scrapy to crawl and return <li class="class1 class2 class3"><\li>
I encountered some phenomenon that the web page source code is different from the source code I crawled.
Main issue is your <li><\li> is not valid HTML like <li></li> and xpath should look like:
.//li[contains(#class, 'class1') and contains(#class, 'class2')]
May use a tool like xpather to check if a path works or not.

Python Selenium Click Link by href

There are a lot of methods I've tried for clicking on the link generated by the HTML bellow
<a class="btn btn--primary welcomePageButton" href="#/dispatchlist">
<span class="">View Dispatches/Invoices</span>
</a>
I've tried
driver.find_element_by_xpath("//a[contains(#href,'dispatchlist')]").click()
driver.find_element_by_link_text("View Dispatches/Invoices").click()
driver.find_element_by_partial_link_text("View Dispatches").click()
And in every case, I got NoSuchElementException.
Can you please guide me to solve this?
PS: I used the latest version of Google Chrome.
After trying a lot of xpaths, I decided to use JS snippets which worked like a charm
driver.execute_script("document.getElementsByClassName('btn')[0].click()")
However, thanks, everyone.

How to write dynamic xpath for img src

i am trying to automate couple of Selenium-TestNg scenarios from the website - http://ecommerce.saipratap.net/checkpersonaldetail.php
I was trying to click on the "continue "button, but it seems to be an image.
Below is the snippet of the code. How to write the xpath for the same?
tried using the xpath - //a[contains(#href,'checkoutshiping.php')], but it didnt work
<a href="checkoutshiping.php"> ==$0
<img src="images/continue.gif" border="0"
style="cursor:hand;"> ==$0
</a>
Are you sure the user is logged in? I see other set of tags when check the website.
Have you tried below xpath.
//*[.='Checkout']
Use - //a[#href = "checkoutshiping.ph"], its gonna find your button. I checked it on your website.
Here is example from your website

Capybara: Find element with unknown tag

I want to find an element that has a ng-model attribute with Capybara. I dont know the tag of the element, how can I still search for the element?
Thanks!
Found the answer, if anyone is interested:
find(:css, "input[ng-model]")
works also without using a tag:
find(:css, "[ng-model]")
Sometimes its really just simple.

How can I access a button to click it with following code in selenium webdriver?

There are many buttons sharing the same class.
May have to go with clicking the link /account/logout'.
This is the code I'm trying to use:
input class="btnRed text-uppercase fo_white" value="Logout" onclick="window.location.href='/account/logout';" type="button"
Hard to say because you didn't provide enough info, but you could probably make it work by using value attribute. Something like this if you are using java.
driver.findElement(By.cssSelector("[value='Logout']")).click();
Not pretty solution, but give it a try:
driver.findElement(By.cssSelector(".btnRed.text-uppercase.fo_white")).click();
Looking at your HTML DOM this command will work for you:
driver.findElement(By.xpath("//input[#value='Logout']")).click();
Let me know if it works for you.
Looking at your HTML, this should work
driver.findElement(By.xpath("//input[#value='Logout'][#type='button']")).click();
Let me know if it works.
Is your element visible/enabled? In order to select an element, it must be present in your DOM. If the element is activated through an event, it cannot be selected until the event occurs.
Take a look at this post. This other post also have good ideas.