Message: no such element: Unable to locate element when click() on element button - selenium-webdriver-python

I would like to be able to click sign in button and I have tried a couple of ways with different types of element like Xpath, name, ID,...:
singin_button = driver.find_element(By.XPATH,
"//div[#class='wpfe-logon-view-demo-request-buttons']").click()
but i got the issue:
selenium.common.exceptions.NoSuchElementException: Message: no such
element: Unable to locate element:
{"method":"xpath","selector":"//div[#class='wpfe-logon-view-demo-request-buttons']"}
Could u point me to right direction? Many thanks!

Related

Unable to click "Accept all" cookies in Selenium(python) in a pop-up

I am trying to click the Accept button on the pop-up for cookies.
Here's the code that I have tried:
driver.get(r'https://www.studydrive.net/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.sc-gtsrHT.iETHdM"))).click()
Here's the error:
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
I have also tried using X-path but was not able to click on the button.
Any help is highly appreeciated.
This pop-up is on the shadow dom.
Selenium does not provide explicit support to work with Shadow DOM elements, as they are not in the current dom. That's the reason why we will get NoSuchElementException exception when try to access the elements in the `shadow dom.
With the following JavaScript this should work:
driver.get(r'https://www.studydrive.net/')
time.sleep(5)
accept_all_btn = driver.execute_script('''return document.querySelector('#usercentrics-root').shadowRoot.querySelector('button[aria-label="Accept All"]')''')
accept_all_btn.click()
See more explanations here and here

Getting an error when clicking a link element on a web page by a Selenium script

When my Selenium script clicks a link element presented on a web page by click() method, I am getting the below error:
org.openqa.selenium.WebDriverException: Element is not clickable at point (36, 72).
This is my HTML code
<div id="targettab">
Book
</div>
This is my Selenium code:
driver.findElement(By.id("highlight-book")).click();
What am I doing wrong here? Could you please advise me about possible solutions? Thanks.
If element is present in lot of nested divs, rarely selenium driver will fails to click element. You can try clicking using Enter button.
driver.findElement(By.id("highlight-book")).sendKeys(Keys.Return);

WebElement is identified through xpath in the developer console but the element wont be identified through selenium findElement method

The html element Im trying to locate is the "Shared" link.
I wrote a dynamic xpath to locate the element and it shows as the element was identified in the developer console.
But when i use the xpath that i wrote in the developer console to locate the element using selenium, it does not locate the element.
The method i used to check if it locates the element is shown below.
I could not figure out why this issue occurs, Is it because of a issue in the xpath that i have written or because of another issue?
Code you can try out is :
new WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath(" your Xpath ")));
driver.findElement(By.xpath("your Xpath")).click();
The Xpath you have written would work if only one title is present on current page.
driver.find_elements doesn't have attribute to click() so use driver.findElement instead of Elements

Find web element xpath for button

not able to locate the web element "Next" button, where the Absolute xpath for the button is
//*[#id="RULE_KEY"]/div/div/div/div/div/div/div/div/div/div/div/div/div/div/div/div/span/button/div/div/div/div
Provide the relative xpath, But i tried with the below one which is not working - xpath =
"//span[contains(text(),'Next >>')]"
Try following xpath
//*[#id="RULE_KEY"]//button//span[contains(text(),'Next >>')]

Selenium Webdriver -- No such Element

I am trying to login into Sears.com using Selenium webdriver.clicked on Sign in link-->login form opens.
But unable to locate the text box element inside the login form. The login form is inside an iframe (frame Name =easyXDM_default5914_provider).This iframe is inside div (id=modaliframe)
driver.switchTo().frame(driver.findElement(By.xpath(".//iframe[#id='easyXDM_default5914_provider']")));
driver.switchTo().activeElement();
driver.findElement(By.id("email")).sendKeys("xxx#gmail.com");
Getting below exception in my console:
org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"id","selector":"email"}
Try with the below code.
driver.get("http://www.sears.com/");
driver.findElement(By.xpath("//*[#id='header-shop-your-way-partner']")).click();
driver.findElement(By.xpath("//*[#id='open-sign-in-form']/span[2]")).click();
driver.switchTo().frame("registration-form-iframe");
driver.findElement(By.xpath("//*[#id='email']")).sendKeys("abcd#gmail.com");
Thread.sleep(3000);