Here is the code for the button
<li class="selected ng-binding" ng-bind="text.loginLink">Click Me</li>
How can I click this type of button. I have tried
button = driver.find_element_by_xpath('//li[contains(text(),"Click Me")]')
but it is not working. What can I do ?
Try this xpath :
//span[contains(text(),"Click Me")]
driver.find_element_by_xpath("//li[contains(text(),'Click Me')]").click()
Try below xpaths, if not please provide the html source for the parent element's as well.
//li[.='Click Me']
//li[contains(text(),'Click Me')]
//li[#ng-bind="text.loginLink"]
Related
How to find selector from this? I want to click the button but unable to find selector.it will be a css selector or class selector.
HTML
<button data-bb-handler="confirm" type="button" class="btn btn-success">Continue and Logout Other User</button>
You can try it
button_Login = driver.find_element_by_css_selector("#button").text("Continue and Logout Other User")
Make sure the button is visible when you try to click it.
The following selectors should work:
.btn-succes
//button[#class='btn btn-succes']
You can use the following selectors -
driver.find_element(By.CSS_SELECTOR,'button.btn.btn-success')
driver.find_element(By.CSS_SELECTOR, 'button[class='btn btn-success']')
driver.find_element(By.XPATH, "//button[normalize-space()='Continue and Logout Other User']")
I'm trying to automatically navigate web pages using python, selenium, xpath.
I want to click a next page button in a page whose code is like this:
<a _ngcontent-pnd-c43="" automation-id="discover-market-next-button"
class="menu-item-button ng-star-inserted">
<span _ngcontent-pnd-c43="" class="nav-button-right sprite"></span>
</a>
I tried with the following code:
try:
element='//span[class="nav-button-right sprite"]'
button_next = driver.find_element_by_xpath(element)
webdriver.ActionChains(driver).move_to_element(button_next).click(button_next).perform()
time.sleep(15)
content = driver.page_source.encode('utf-8')
except NoSuchElementException:
print ("NoSuchElementException")
but I got "NoSuchElementException".
Could anyone help me?
The problem is that nav-button-right sprite is not a class, not even an attribute name. So try changing you xpath expression from:
element='//span[class="nav-button-right sprite"]'
to:
element='//span[#_ngcontent-pnd-c43]'
and see if it works.
You less # in:
element='//span[#class="nav-button-right sprite"]'
I think the problem is in your XPath, you missed # symbol after class, try this hope it helps:
element='//span[#class='nav-button-right sprite']'
I am trying to click a button from the Linkedin public page feed
https://www.linkedin.com/company/bbc-news/
and the button is a post's toolbar button with 3 dots
here is the sample screenshot
and my code is
self.browser.execute_script("document.getElementsByClassName('feed-shared-control-menu__trigger artdeco-button artdeco-button--tertiary artdeco-button--muted artdeco-button--1 artdeco-button--circle artdeco-dropdown__trigger artdeco-dropdown__trigger--placement-bottom ember-view')[1].scrollIntoView();")
self.browser.execute_script("document.getElementsByClassName('feed-shared-control-menu__trigger artdeco-button artdeco-button--tertiary artdeco-button--muted artdeco-button--1 artdeco-button--circle artdeco-dropdown__trigger artdeco-dropdown__trigger--placement-bottom ember-view')[1].click();")
it doesn't return any errors
please kindly help me solve this issue
Thanks in advance for any help
Note: I have already tried webDriverwait , find_elements_by_class_name
The element has an id associated to it, so you can use that id to get the xpath of the element and then you can click it. Also, it is recommended to use the selenium click instead of the javascript executor click(which you are currently using).
Your code should be like:
self.browser.find_element_by_xpath("//button[#id='ember160']//li-icon").click()
If you want to use javascript executor click, then your code should be like:
element = self.browser.find_element_by_xpath("//button[#id='ember160']//li-icon")
driver.execute_script("arguments[0].click();", element)
I cannot create the .click()-action on the button.
HTML:
<button class="btn__type btn__type_close">Закрыть</button>
I try to make an element clickable for execute_script:
driver.execute_script("return document.getElementsByClassName('.btn__type_close')").click()
My code using Selenium:
driver.find_element_by_css_selector('button.btn__type_close').click()
None of the methods is working.
Question: How will it be correct?
Did you try clicking using XPath?
WebElement btnClose=driver.findElement(By.xpath("//button[#class='btn__type btn__type_close']"));
if(btnClose.isEnabled()){
btnClose.click();
}
This is element HTML:
<button class="search-vertical-filter__filter-item-button button-tertiary-medium-muted" data-ember-action="" data-ember-action-5975="5975"> Content </button>
Code:
driver.find_element_by_link_text('Content').click()
Even i also tried:
driver.find_element_by_class_name('search-vertical-filter__filter-item-button button-tertiary-medium-muted').click()
I want to click on "Content" button on LinkedIn automatically and I am using Selenium and Python for that.
Try to use the following code:
driver.find_element_by_css_selector(".search-vertical-filter__filter-item-button.button-tertiary-medium-muted").click()
Hope it helps you!
As per the HTML provided to click on the button with text as Content you can use the following line of code :
driver.find_element_by_xpath("//button[#class='search-vertical-filter__filter-item-button button-tertiary-medium-muted' and normalize-space()='Content']").click()