I hope you are all doing well.
I am facing an error during web scraping in R using the Selector Gadget Tool where when I am selecting the data using the tool on the Coursera website, the no. of values it shows is correct (10). But when I copy that particular CSS code in R and run it, it's showing 18 names in the list. Please if anyone can help me with this. Here is a screenshot of the selector gadget output:
And here is what gets returned in R when I scrape that css selector:
The rendered content seen via a browser is not exactly the same as that returned by an XHR request (rvest). This is because a browser can run JavaScript to update content.
Inspect the page source by pressing Ctrl+U in browser on that webpage.
You can re-write your css selector list to match the actual html returned. One example would be as follows, which also removes the reliance on dynamic classes which change more frequently and would break your program more quickly.
library(rvest)
read_html("https://in.coursera.org/degrees/bachelors") |>
html_elements('[data-e2e="degree-list"] div[class] > p:first-child') |>
html_text2()
Learn about CSS selectors and operators here: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors
I am new to Rails and Selenium but have used other automated testing tools.
I exported a script from the Selenium 2 IDE to Rails/RSpec and am altering the code to get it to run. The script fails to find a specific link.
The original Ruby code as exported from the working IDE script was:
#driver.find_element(:link, "skip").click
This failed, so I attempted to identify the element with an XPath statement. (There were other elements that failed in the originally exported code that I fixed by using XPath, so that’s why I am using this strategy.)
I tried different alternatives to identify the link in the Ruby code, such as:
Attempt #1:#driver.find_element(:XPath, "//*[#class='skip-link']").click
Attempt #2:#driver.find_element(:XPath, "//*[#value='skip']").click
Result in all cases: Unable to locate element: {"method":"link text","selector":"skip"}
HTML reported per Firebug:
<a style="float: right; margin-right: 10px; text-decoration: none;" href="/yourfuture" class="skip-link"> skip </a>
XPath reported per Firebug:
/html/body/div[2]/div[2]/div/div/div[3]/div[4]/a
I have timeout set to 60 seconds and see the link skip displayed for several seconds before the script fails, so I don’t this is an issue.
One possibly relevant fact: when the app presents the window with all the controls, the skip does not appear initially. By program design, the app waits about 5 seconds before.
What am I doing wrong? Thanks in advance.
It turns out the link that was not seen was in an iFrame. The attributes of the iframe changed so it was difficult to identify it with a static property, so I just inserted the following line of code just before the line that Webdriver could not "see":
#driver.switch_to.frame(0)
I could have also used #driver.switch_to.frame("iframe-identifier-per-swtich") if there was a reliable way of identifying the iframe.
Yeah, you probably knew that but maybe this will help another newbie avoid the same problem.
I'm trying to assert the current styling of a div. For example, is it set to visible or not. I wasn't able to find a way in jwebunit to get at this information though. Ideas? Alternate approaches?
Constraint: I cannot change the page I am trying to test.
There are two TestEngines which you can use with JWebUnit, HTMLUnit and Selenium. why not System.out.println("========="+ getPageSource()); and see if the page source return from both TestEngines gives css within the output. If they do that means you can verify css, if the output does not give css then i guess you will not be able to verify. One thing i know for sure is that it will show you the css file the page uses for style but as to the styling being applied I will say not, but try it
How to create a bookmarklet like this one: http://www.vimeo.com/1626505
I want to create one the same, where to start? i want to know the work flow of how this one is working to build my own.
Thanks
A bookmarklet is just a javascript program written on a single line of code replacing the usual location attribute (http://www.somestuffhere.com) on a bookmark.
To build your own bookmarklet, I suggest you to use Firebug :
- type your code inside firebug and execute it until what you want to do is working,
- then, remove all new lines in order to have a big one line piece of code,
- create a new bookmark in your browser and, in the location field, write javascript: and copy-paste your single line of code.
You can try a simple bookmarklet by typing that directly in your browser location bar : javascript: alert('this is a very simple bookmarklet'); then type enter to execute it.
Here is a handy bookmarket builder I have sometimes used. It can squash many lines of javascript into one line that can be set as the 'target' of a bookmark
(there may very well be better ones out there than this, but its done the job well for me)
I have a legacy application that I needed to implement a configuration page for to change text colors, fonts, etc.
This applications output is also replicated with a PHP web application, where the fonts, colors, etc. are configured in a style sheet.
I've not worked with CSS previously.
Is there a programatic way to modify the CSS and save it without resorting to string parsing or regex?
The application is VB6, but I could write a .net tool that would do the css manipulation if that was the only way.
You don't need to edit the existing one. You could have a new one that overrides the other -- you include this one after the other in your HTML. That's what the "Cascading" means.
It looks like someone's already done a VB.NET CSS parser which is F/OSS, so you could probably adapt it to your needs if you're comfortable with the license.
http://vbcssparser.sourceforge.net/
One hack is to create a PHP script that all output is passed through, which then replaces certain parts of CSS with configurable alternatives. If you use .htaccess you can make all output go through the script.
the best way i can think of solving this problem is creating an application that will get some values ( through the URL query ) and generate the appropriate css output based on a css templates
Check this out, it uses ASP.NET and C#.
In my work with the IE control (shadocvw.dll), it has an interesting ability to let you easily manage the CSS of a page and show the effects of modified CSS on a page in realtime. I've never dealt with the details of such implementations myself, but I recommend that as a possible solution worth looking at. Seeing as pretty much everyone is on IE 6 or later nowadays, you can skip the explanations about handling those who only have IE 5,4,3 or 2 installed.
Maybe the problem's solution, which is most simple for the programmer and a user is to edit css via html form, maybe. I suppose, to create css-file, which would be "default" or "standart" for this application, and just to read it, for example, by perl script, edit in html and to write it down. Here is just the simple example.
In css-file we have string like:
border-color: #008a77;
we have to to read this string, split it up, and send to a file, which will write it down. Get something like this in Perl:
tr/ / /s;
($vari, $value) = split(/:/, _$);
# # While you read file, you can just at the time to put this into html form
echo($vari.":<input type = text name = ".$vari." value = ".$value.">");
And here it is, you've got just simple html-form-data, you just shoul overwrite your css-file with new data like this:
...
print $vari[i].": ".$value.";\n";
...
and voila - you've got programmatical way of changing css. Ofcourse, you have to make it more universal, and more close to your particular problem.
Depending on how technically oriented your CSS editors are going to be, you could do it very simply by loading the whole thing up into a TextEdit field to let them edit it - then write it back to the file.
Parsing and creating an interface for all the possibilities of CSS would be an astronomical pain. :-)