I don't usually post on here as you all seem pretty advanced for me, but this feels like an advanced question, so thought I'd ask.
I'm using the Content Egg plugin for WordPress (please don't roll eyes) and it's asking me for XPath for a price I'm trying to get. I have tried so many different xpaths and none of them seem to be working. I'm trying to get the price Xpath from this webpage. Any ideas?
https://www.hockeydirect.com/Catalogue/Hockey-Sticks/Young-Ones-Hockey-Sticks/Young-Ones-ABD-Hockey-Sticks/Young-Ones-ABD-70-Hockey-Stick-341111
This is what i've tried:
//html/body/form/div[5]/div[2]/div[3]/div/span/div[1]/div[4]/div[2]/div[2]/div/div[1]/div/span/fieldset/div[1]/div/div[1]
//*div[#class="MainPriceContainer"]
//div[#class='MainPriceContainer vcenter']
Any help would be greatly appreciated.
try to copy the xpath from firefox by this steps
inspect elements and select the price with the selector pointer it will highlight the element in the inspector html
then right click to the highlighted code then copy then select XPATH from inside copy
then paste it to the Xpath
then set the price update in the offer module setting to 30 seconds and test
if worked tell me :)
Related
Hey everyone! Today I am working with Python 3 and Selenium web driver. I am encountering a problem with finding by element. Here is the HTML:
<a _ngcontent-pxc-c302="" class="name ng-star-inserted" href="/person/20d4a795d3fb43bdbee7e480df27b05b">michele regina</a>
The goal is to click on the first name that appears in a listed column.
The name changes with every page refresh. This comes with two problems in that the link text is the name and it changes, and the link constantly changes as well for each different name except for the part that says /person/
I tried the following:
driver.find_element_by_css_selector("a.name ng-star-inserted").click()
driver.find_element_by_class_name("name ng-star-inserted").click()
Which resulted in an element that is not a clickable error.
I also tried xpath by copying and pasting the entire XPath copied from Google inspector... lol
driver.find_element_by_xpath('/html/body/app-root/app-container/div/div/tc-app-view/div/div/div/ng-component/mat-sidenav-container/mat-sidenav-content/div/div[2]/tc-person-table-container/tc-collapse-expand[1]/section/tc-person-table/table/tbody/tr[1]/td[2]/tc-person-table-cell/a').click()
and it kind of works sometimes, which is weird but I am sure there has to be a better way. Thank you so much in advance! Any help is appreciated! Also, I am very new to Python, I know zero HTML, and I am also newer to stack! Thanks!
From the given full xpath the a tag you are looking for is in table,section,div. Look for an id in those tags and trace the a.
Iv been trying to get the form elements on this website and for some reason I cant get them. Iv tried every way I can think of. I would really appreciate some help.
Here is my latest attempt
inputs = driver.find_elements_by_xpath("//input[#type='text']")
Here is the website.
Thanks in advance.
Edit : Github link for project
Edit : Ok so I found out that if you go straigt to website that the btn points to then it works. So I am assuming that slenium does not automaticly update to the HTML of the current page. How does one do this?
if you are getting 'NoSuchElementException', try using conditional wait before you do find_element. When you are loading another page wait until the element is visible and can be interacted.
Guide for that is here
check if the element is inside in iform, if so use
driver.switchTo().frame("framename")
EDIT
Focus on something unique in the tag. For your example use the class name used in the div. Do not use the ID tag identifier as it changes over time.
//*[contains(#class, 'ginput_container ginput_container_text')]/following::*[contains(text(),'Email')]/following::div[1]/descendant::input
I am unsure if any of you are familiar with Reddit, however I want to start a small subreddit for some warhammer lore questions, where people can post questions and then answer them. To highlight the questions that are answered I want a moderator account to automatically upvote them once they are "Solved", which I am trying to do with Selenium, however I am running into some troubles finding the upvote button.
Currently, I am able to log in with my moderator account, however I am unable to press the upvote button, I have tried the following code to no avail:
driver.get("https://www.reddit.com/r/ChosenSub/ChosenThread")
time.sleep(3)
driver.find_element_by_xpath("div[#id='siteTable']/div[#id='thing_t3_XXXXXX']/div[#class='midcol unvoted']/div[#class='arrow up login-required access-required']").click
Where the XXXXX is an id of the thread in question, however this produces absolutely no result. I am fairly familiar with Python, but in no way xPath, I used the XPath helper tool in Chrome to get the XPath above, but still no luck
If anyone has any potential ideas please do let me know, any and all help is very appreciated.
Considering provided in comments link, you can try to use simplified XPath as below:
driver.find_element_by_xpath("//div[#id='thing_t3_XXXXXX']//div[#aria-label='upvote']").click()
If you need more common method to upvote question by its id (if id value is predefined):
def upvote_question(question_id):
driver.find_element_by_xpath("//div[#id='%s']//div[#aria-label='upvote']" % question_id).click()
And then you can just use it with a question's id as argument:
upvote_question("thing_t1_dcjl4vu")
You probably need to add '//' in front of that xpath so that it finds the div anywhere in the document, otherwise it would have to be at the root of the html (which it most likely is not). So the xPath would be:
"//div[#id='siteTable']..."
I want to scrape the email address from the following web page.
Facebook Business Info Page
So I decided to use the selenium driver with Python. I figured the best way to do this was through defining the xpath. From inspection of the elements, I noticed that the info I was looking for was found in the following HTML structure as seen here:
Now I must admit that I am bit of a noob when it comes to using Selenium and defining elements by xpath, so I was hoping someone would correct me if I am defining the following xpath incorrectly. This is what I have right now:
But I'm fairly certain I'm defining the wrong xpath. I know I want to grab the information in the _50f4 div class but I don't know how to define it. If someone could help me figure that out I would greatly appreciate it.
you can get the text of the email address using an xpath like : //div[#id = 'u_0_u']//ul/li[4]//div[#class = '_50f4']
im new to selenium and I am trying to click on an image but when I inspect the element it only has a title, an src=, and an alt=. I would like to use xpath but am unsure exactly how it works on python, on java i would do driver.findElement(By.xpath("//img[#title='']")) but I am unsure of how to do it on python any help is appreciated :)
In Python, there is the find_element_by_xpath() shortcut method:
driver.find_element_by_xpath("//img[#title='']")
Note that your locator does not look quite reliable. Providing the relevant HTML of the image and its parents might help us to provide you with a better option.