find_element_by_partial_link_text ascii code issue - python

http://www.m2sys.com/.
When I click on CloudApper™ under Solutions I get an ascii code error.
I find the element using:
driver.find_element_by_partial_link_text('CloudApper™')
How can I click the partial link?

Just ignore the TM in superscript while searching for CloudApper™.
driver.find_element_by_partial_link_text('CloudApper')
There are two instances by link text CloudApper™ in the target page. You can use this for finding the link cloudApper located below solutions. driver.find_element_by_xpath("//ul[#id='mobile-advanced']//a[contains(#href,'cloudapper')]")

CloudApper™ is a label, you have to click logo, use this xpath
//a[#href='http://www.m2sys.com/cloudapper-modularized-framework-enterprise-cloud-application/']

Try the following,
first, you need to interact with the menu:
driver.find_element_by_id("menu-item-15554").click();
then click on the actual element:
driver.find_element_by_xpath("//a[contains(#href, 'cloudapper-modularized-framework-enterprise-cloud-application')]").click();

Related

Selenium - Get element after a specific element (Python)

As you can see from the picture, the pagination is a bit different. So my idea is to get the position of the current-page and get the link for the a tag.
current_page= driver.find_element(By.CSS_SELECTOR,"span.current-page")
driver.find_element(By.TAG_NAME,"a").click()
but I didn't know to use the current_page element to find the a tag after it and click on it.
Thanks for your help in advance.
To get the next element using current page reference you can use the following css selector in one liner or XPATH option.
next_page= driver.find_element(By.CSS_SELECTOR,"span.current-page+a")
print(next_page.get_attribute("href"))
next_page.click()
Or you can use this.
current_page= driver.find_element(By.CSS_SELECTOR,"span.current-page")
current_page.find_element(By.XPATH,"./following::a[1]").click()

Element not found when using webdriver with Selenium in Python

got a problem with my code and I need your help. What I'm trying to do is the following:
1- access a website;
2- fill the registration form: name, email, password, etc.
Step 1 works; after clicking the sign up button, the form will pop up in a new tab.
Step 2; when trying to find the elements, by, id or name, I get the error "selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element"
My code is the following:
driver.find_element_by_link_text('Sign Up').click()
time.sleep(3)
driver.find_element_by_id("signup_title").send_keys(signup_tile)
driver.find_element_by_id("signup_name").send_keys(signup_name)
Attached you can find the html. Thank you in advance, much appreciated your help.
Note
In console I tried to find the element searching the id using
$x("//*[#id='signup_title']") and it was found: [input#signup_title.sc-AxirZ.kzqQJb.invalid]. Also the element is loaded.
HTML
Try using:
driver.find_element_by_xpath("<XPath>")
It seems to work better. To get the XPath of an element, find the element in the inspector, right-click it then Copy -> Copy XPath. If that doesn't work, select Copy Full XPath instead
The problem was related to the second tab; because the form opens in another tab, the window must be switched in the code.
I used the following:
driver.switch_to.window(driver.window_handles['Nr']), Nr being the index for the tab- if there are 2, the main one, and the second one-in my case with the form, the index will pe 1-counting starts from zero.

Cannot find element by name

the code:
I want to change the value of this textbox, but I can't do it.
Here is my code for it:
driver.find_element_by_name("inps_19_1").send_keys("value", "my value"), not working,
driver.find_element_by_css_selector("input[name='inps_19_1']").send_keys("whatever") not working.
Any advice?
I can't see the full HTML, but a problem I've run into a number of times was either elements being contained iframes or shadowroots that you'd have to switch to before the driver can find it. iframes are easy enough to switch to
driver.switch_to_frame("frameName")
Then you can find the element after.
If the element is contained within a shadowroot, this answer shows how to expand them https://stackoverflow.com/a/37253205/10007528

Python + Selenium: How can click on "onclick" elements?

I have an "onclick" element in a webpage whose HTML reads as follows:
Fastener
I want to search this element using the string "fastener" or "Fastener" using Python + Selenium. The number "3625" will change depending on previous inputs, and hence cannot be searched for.
I tried the following, but in vain:
br.find_element_by_css_selector("a[#onlick*='fastener']").click()
Please suggest ways to do this. Thank you!
P.S.: I am using Python 2.7, with Chrome WebDriver and Chrome v62.
To search the element with text as Fastener you can use either of the following options :
Through Fastener :
br.find_element_by_link_text("Fastener").click()
Using onclick through fastener (xpath):
br.find_element_by_xpath("//a[contains(#onclick,'fastener')]").click()
Using onclick through fastener (css_selector):
br.find_element_by_css_selector("a[onclick^='fastener']").click()
Use the following code for that:
br.find_element_by_link_text("Fastener").click()
Hope it helps you!
Using capybara-py:
page.click_link("Fastener")
Capybara is designed to provide this and many other similar helper methods, such as one might need to write acceptance tests from the perspective of end users:
page.fill_in("Street", value="123 Main St")
page.select("United States", field="Country")
page.choose("Expedited shipping")
page.click_button("Place order")
Use contains to search element
//a[contains (#onclick='fastener')]
OR
//a[contains(text(),"Fastener")]

How to find href through class name and click with selenium

I'm using Selenium with python to make a spider.
A part of the web page is like this:
text - <span class="sr-keyword">name</span> text
I need to find the href and click.
I've tried as below:
target = driver.find_element_by_class_name('_j_search_link')
target.click()
target is not None but it doesn't seem that it could be clicked because after target.click(), nothing happened.
Also, I've read this question: Click on hyperlink using Selenium Webdriver
But it can't help me because in my case, there is a <span class>, not just a simple text Google.
You can look for an element with class _j_search_link that contains text Wat Chedi Luang
driver.find_element_by_xpath('//a[#class="_j_search_link" and contains(., "Wat Chedi Luang")]')
driver.find_elements_by_partial_link_text("Wat Chedi Luang").click()
I think you didn't find right element. Use CSS or Xpath to target this element then click it, like:
//a[#class='_j_search_link']
or
//a[#class='_j_search_link']/span[#class='sr-keyword']

Categories

Resources