Selenium unique element not returned by span text
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
On a web page, this element is the only one containing the exact text 'Volgende stap':
<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>
But when I try to select (a list of) the elements containing these words using xpath:
driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")
I keep getting an empty list (or element not found
in case of find_element
instead of find_elements
).
This is the script leading to the html page I'm working on:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()
python selenium xpath css-selectors webdriverwait
add a comment |
On a web page, this element is the only one containing the exact text 'Volgende stap':
<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>
But when I try to select (a list of) the elements containing these words using xpath:
driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")
I keep getting an empty list (or element not found
in case of find_element
instead of find_elements
).
This is the script leading to the html page I'm working on:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()
python selenium xpath css-selectors webdriverwait
so if I go to that page and manually click on/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148
and search forVolgende
on either visible page, or page source, nothing comes up.
– Kiril S.
Nov 13 '18 at 23:36
add a comment |
On a web page, this element is the only one containing the exact text 'Volgende stap':
<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>
But when I try to select (a list of) the elements containing these words using xpath:
driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")
I keep getting an empty list (or element not found
in case of find_element
instead of find_elements
).
This is the script leading to the html page I'm working on:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()
python selenium xpath css-selectors webdriverwait
On a web page, this element is the only one containing the exact text 'Volgende stap':
<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>
But when I try to select (a list of) the elements containing these words using xpath:
driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")
I keep getting an empty list (or element not found
in case of find_element
instead of find_elements
).
This is the script leading to the html page I'm working on:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()
python selenium xpath css-selectors webdriverwait
python selenium xpath css-selectors webdriverwait
edited Nov 14 '18 at 7:00
DebanjanB
46.9k134790
46.9k134790
asked Nov 13 '18 at 22:02
DaRealDaReal
148317
148317
so if I go to that page and manually click on/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148
and search forVolgende
on either visible page, or page source, nothing comes up.
– Kiril S.
Nov 13 '18 at 23:36
add a comment |
so if I go to that page and manually click on/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148
and search forVolgende
on either visible page, or page source, nothing comes up.
– Kiril S.
Nov 13 '18 at 23:36
so if I go to that page and manually click on
/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148
and search for Volgende
on either visible page, or page source, nothing comes up.– Kiril S.
Nov 13 '18 at 23:36
so if I go to that page and manually click on
/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148
and search for Volgende
on either visible page, or page source, nothing comes up.– Kiril S.
Nov 13 '18 at 23:36
add a comment |
2 Answers
2
active
oldest
votes
As per the HTML the desired element with text as Volgende stap is within an <iframe>
so you have to:
- Induce WebDriverWait for the desired frame to be available and switch to it.
- Induce WebDriverWait for the desired element to be clickable.
You can use the following solution:
Using
CSS_SELECTOR
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()Using
XPATH
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Here you can find a relevant discussion on Ways to deal with #document under iframe
I see, so it was because of an Iframe. Thanks for the explanation and link to more information.
– DaReal
Nov 14 '18 at 18:56
add a comment |
It's in an iframe. Switch to it first, then try and find via text:
frame = driver.find_element_by_css_selector('frame.personalize--frame')
driver.switch_to.frame(frame)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290184%2fselenium-unique-element-not-returned-by-span-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As per the HTML the desired element with text as Volgende stap is within an <iframe>
so you have to:
- Induce WebDriverWait for the desired frame to be available and switch to it.
- Induce WebDriverWait for the desired element to be clickable.
You can use the following solution:
Using
CSS_SELECTOR
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()Using
XPATH
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Here you can find a relevant discussion on Ways to deal with #document under iframe
I see, so it was because of an Iframe. Thanks for the explanation and link to more information.
– DaReal
Nov 14 '18 at 18:56
add a comment |
As per the HTML the desired element with text as Volgende stap is within an <iframe>
so you have to:
- Induce WebDriverWait for the desired frame to be available and switch to it.
- Induce WebDriverWait for the desired element to be clickable.
You can use the following solution:
Using
CSS_SELECTOR
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()Using
XPATH
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Here you can find a relevant discussion on Ways to deal with #document under iframe
I see, so it was because of an Iframe. Thanks for the explanation and link to more information.
– DaReal
Nov 14 '18 at 18:56
add a comment |
As per the HTML the desired element with text as Volgende stap is within an <iframe>
so you have to:
- Induce WebDriverWait for the desired frame to be available and switch to it.
- Induce WebDriverWait for the desired element to be clickable.
You can use the following solution:
Using
CSS_SELECTOR
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()Using
XPATH
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Here you can find a relevant discussion on Ways to deal with #document under iframe
As per the HTML the desired element with text as Volgende stap is within an <iframe>
so you have to:
- Induce WebDriverWait for the desired frame to be available and switch to it.
- Induce WebDriverWait for the desired element to be clickable.
You can use the following solution:
Using
CSS_SELECTOR
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()Using
XPATH
:WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Here you can find a relevant discussion on Ways to deal with #document under iframe
answered Nov 14 '18 at 7:06
DebanjanBDebanjanB
46.9k134790
46.9k134790
I see, so it was because of an Iframe. Thanks for the explanation and link to more information.
– DaReal
Nov 14 '18 at 18:56
add a comment |
I see, so it was because of an Iframe. Thanks for the explanation and link to more information.
– DaReal
Nov 14 '18 at 18:56
I see, so it was because of an Iframe. Thanks for the explanation and link to more information.
– DaReal
Nov 14 '18 at 18:56
I see, so it was because of an Iframe. Thanks for the explanation and link to more information.
– DaReal
Nov 14 '18 at 18:56
add a comment |
It's in an iframe. Switch to it first, then try and find via text:
frame = driver.find_element_by_css_selector('frame.personalize--frame')
driver.switch_to.frame(frame)
add a comment |
It's in an iframe. Switch to it first, then try and find via text:
frame = driver.find_element_by_css_selector('frame.personalize--frame')
driver.switch_to.frame(frame)
add a comment |
It's in an iframe. Switch to it first, then try and find via text:
frame = driver.find_element_by_css_selector('frame.personalize--frame')
driver.switch_to.frame(frame)
It's in an iframe. Switch to it first, then try and find via text:
frame = driver.find_element_by_css_selector('frame.personalize--frame')
driver.switch_to.frame(frame)
answered Nov 14 '18 at 1:23
Lucas TierneyLucas Tierney
1,65288
1,65288
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290184%2fselenium-unique-element-not-returned-by-span-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
so if I go to that page and manually click on
/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148
and search forVolgende
on either visible page, or page source, nothing comes up.– Kiril S.
Nov 13 '18 at 23:36